Search code examples
objective-cios7uiviewcontrolleruinavigationcontrollermodalviewcontroller

Root view disappearing


I have the below code to test some modal presentation. I'm attempting to present a UBSLoginViewController via a UINavigationController, then modally present a UBSLoadingViewController with transparent background over the UBSLoginViewController, wait some time, then dismiss it.

What happens:

  1. Login view displays,

  2. Loading view displays transparent over login view,

  3. Login view disappears or transparency disappears on loading view. Either way, login view is no longer visible behind loading view.

  4. No dismissal of loading view.

I do get two warnings below. One comes at the first presentation of the login view, the second on attempt to dismiss (warning 1 on bottom):

2014-08-22 11:37:52.525 Uberscore[72349:60b] Warning: Attempt to dismiss from view controller <UINavigationController: 0x8c4cfc0> while a presentation or dismiss is in progress!
2014-08-22 11:37:53.088 Uberscore[72349:60b] Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0x8c4cfc0>.

Code below:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //Prep window
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    //Set up and display login controller
    UBSLoginViewController* loginView = [[UBSLoginViewController alloc] initWithNibName:LOGINVIEW bundle:nil];
    UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:loginView];
    navigation.navigationBarHidden = YES;
    self.window.rootViewController = navigation;
    [self.window makeKeyAndVisible];
    [loginView presentViewController:[[UBSLoadingViewController alloc] initWithNibName:LOADINGVIEW bundle:nil] animated:YES completion:nil];
    int timeout = 3000;
    wait(&timeout);
    [loginView dismissViewControllerAnimated:YES completion:nil];
    return YES;
}

Solution

  • You're dismissing the loginView with this line:

    [loginView dismissViewControllerAnimated:YES completion:nil];
    

    You want to call dismissViewControllerAnimated:completion: on the loading view instead.

    UBSLoadingViewController *loadingView = [[UBSLoadingViewController alloc] initWithNibName:LOADINGVIEW bundle:nil];
    [loginView presentViewController:loadingView animated:YES completion:nil];
    ...
    // Later on to dismiss the loading view
    [loadingView dismissViewControllerAnimated:YES completion:nil];