Search code examples
iphoneobjective-cios4uiviewcontroller

Why can't I launch this modal view from didFinishLaunchingWithOptions?


I am trying to do something pretty easy, in my estimation:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    prefs =  [NSUserDefaults standardUserDefaults];
    BOOL IsLoggedIn = [prefs boolForKey:@"IsLoggedIn"];

    if(IsLoggedIn == NO)
    {
        //Show login controller
        LoginViewController *lvc = [[LoginViewController alloc] initWithNibName:nil bundle:nil];
        [self.tabBarController presentModalViewController:lvc animated:NO];
        [lvc release];
    }
    else if(IsLoggedIn == YES)
    {
        //Continue doing crap
    }

    // Override point for customization after application launch.
    // Add the tab bar controller's current view as a subview of the window
    self.window.rootViewController = self.tabBarController;

    NSArray *tabs =  self.tabBarController.viewControllers;
    UIViewController *tbInvoice = [tabs objectAtIndex:0];
    tbInvoice.tabBarItem.image = [UIImage imageNamed:@"Open-Mail.png"];
    UIViewController *tbClient = [tabs objectAtIndex:1];
    tbClient.tabBarItem.image = [UIImage imageNamed:@"Breifcase.png"];

    [self.window makeKeyAndVisible];
    return YES;
}

When using the debugger, I see it enter if(IsLoggedIn == NO) and run the LoginViewController code, but the view never shows.

It's driving me crazy.

I tried running the code after [self.windoow makeKeyAndVisible], but it didn't change anything.

This code looks like every example I've seen. Can anyone see what I'm doing wrong?

Thanks in advance,

Clif


Solution

  • Hpoe this post will give you some idea.