Question

I think i found a bug in IOS SDK but i'm not sure how to overcome this issue without heavily modifying my code.

The problem? If i present modal view controller, than the user moves the app to background state, When the user comes back to the app, i switch the rootViewController to a different view controller, where i validate the user session and make some more logic. After this step is finished, i replace my original rootViewController. The problem is that the modalViewController that was presented by the rootViewController, is hidden / not showing. when i try to dismiss it it gives me an error that i'm trying to dismiss a view that it isn't visible.

when i try to present it again (or just another view controller for example), it errors me that i try to present view controller when another view controller is presented.

So, i can't dismiss the modal view controller and i can't present a new one.

To summarize, it seems that if you present a modalviewcontroller, than change your rootViewController to another viewcontroller, and restore the original rootViewController -> Any modals that where presented is in kinda limbo state.

Anyone can figure this out? any solution other the "don't replace your rootviewcontroller"?

Thanks alot

Was it helpful?

Solution

Why are you looking for a solution other than "don't replace your rootviewcontroller". That is the correct guidance. It is not a bug in iOS. In general, you should not replace the root view controller.

It sounds like what you really want is a third view controller to serve as the root view controller of the window and manage the Main and Entrance view controllers as children. Try that and also brush up on using View Controllers, and if you run into trouble we can try to help.

View controllers are designed to work in very specific ways and if you misuse them you'll experience all sorts of undesirable effects. Sometimes you'll get away with it at first, by rest assured, down the line, it will come back to bite you.

View Controller Programming Guide

OTHER TIPS

Assuming you want to keep the original approach, where you are swapping between two controllers, as opposed to using a third to manage them, you could dismiss the presented view controller when you return from the background, prior to swapping out the root view controller.

For example, in -applicationWillEnterForeground: of your app delegate:

if (self.window.rootViewController.presentedViewController != nil) {
        // do any tear-down relating to the modally presented view controller
        // Now dismiss it.
        [self.window.rootViewController dismissViewControllerAnimated:NO
                                                           completion:nil];
    }

That'll eliminate the situation that caused the error message about not being able to display a new View Controller because one is already being presented.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top