Search code examples
objective-cios5storyboardxcode-storyboard

iOS Modal dialog via storyboard UITabBarController


storyboard

I'm looking to understand the "best" way to transition to UITabBarController D (the main interface in my application) from either A or B - conditionally going through C.

Meaning I'd like all of the following to be valid.

A -> C -> D
A -> B -> C -> D
A -> B -> D
A -> D

C is a modal dialog which basically asks the user for a piece of missing information if they don't have it set in their profile.

I've tried:

  1. Using a triggered modal segue from D -> C in the viewDidLoad function of D:

    ([self performSegueWithIdentifier:@"ShowNumberDialog" sender:self];)
    
  2. Programatically displaying C as a modal on D in the viewDidLoad function:

    (void)viewDidLoad
    {
        [super viewDidLoad];
    
        NSString *deviceNumber = [[UserModel sharedSingleton] deviceNumber];
        if ([deviceNumber isEqual:[NSNull null]]) {
    
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
            UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"NumberDialog"];
            [vc setModalPresentationStyle:UIModalPresentationFullScreen];
    
            NSLog(@"Showing device number dialog");
           [self presentModalViewController:vc animated:NO];
        }
    }
    

Neither of these, plus uncountably other "hacky" attempts I've made seem to be working. So I assume I'm not understanding something fundamental about the way I'm supposed to do this. Can someone please recommend a better way?


Solution

  • Try moving the code you have in ViewDidLoad to ViewDidAppear:(BOOL)animated. What may be happening is that you are trying to push a modal dialog into the program while the transition to Tab Page D is still occurring which means the application disregards your request to open the modal dialog C as it continues to load D. ViewDidAppear:(BOOL)animated is called when your view is finally visible to the user and fully loaded.