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(开发者_StackOverflow中文版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
I came up with this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//...
if(!loggedIn)
{
// Launch the app with login controller as the rootController
self.window.rootViewController = loginController;
// ...but switch to the original controller as soon as the UI is presented
dispatch_async(dispatch_get_main_queue(), ^{
self.window.rootViewController = originalRootController;
// ...and silently present the login controller again with no noticeable changes
[originalRootController presentViewController:loginController
animated:NO
completion:NULL];
});
}
Hpoe this post will give you some idea.
精彩评论