TIMEX
TIMEX

Reputation: 271924

"Present Modally" does not show when another modal is already presented

In my iOS application, my VC is presenting a modal (A) via code.

However, when I already have another modal presented (B), this one is not showing at all.

However, when (A) is deinitted, I see that (B) also gets deinitted.

How can I make sure that (B) always gets shown, no matter what, and in front of all other modals?

performSegueWithIdentifier(SEGUES.SegueTabBarToBroadcast, sender: view ) 

My TabBarViewController is calling this segue. (The segue is modal according to storyboard).

The problem occurs when one of the view controllers in my TabBar presents a modal. Then, when I try to call performSegueWithIdentifier, the modal doesn't show (but yet deinits when I close the other modal).

I just want this modal to present NO MATTER WHAT. This modal should overlap all other modals.

I also tried this, but the problem persists:

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let bvc = storyboard.instantiateViewControllerWithIdentifier("BroadcastViewController") as! BroadcastViewController
        self.presentViewController( bvc , animated: true, completion: nil)

Upvotes: 1

Views: 2222

Answers (1)

Fahri Azimov
Fahri Azimov

Reputation: 11770

Presenting multiple view controllers as a modal is not good practice. If you want to present your vc no matter what, then you have to understand the hierarchy of your view controllers. Shortly, you can present view controller modally on the vc with view that has a window, and when you have already presented any vc modally, your view controller's view that has presented the vc does not have the window, thus can't present other view controller modally. Conclusion: you can present vc modally from the top-most vc. So, solution would be keeping reference to the top-most vc, and presenting the desired vc from that vc. Another solution would be adding vc's view directly to the main window of the app, but I would not recommend solving your problem that way. Hope, this helps.

Upvotes: 2

Related Questions