2011-03-22 80 views
1

我试图做一些事情很容易,我估计:为什么我无法从didFinishLaunchingWithOptions启动此模式视图?

- (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; 
} 

在使用调试器,我看到它进入if(IsLoggedIn == NO)和运行LoginViewController码,但鉴于从未显示。

这让我疯狂。

我试着在[self.windoow makeKeyAndVisible]之后运行代码,但它没有改变任何东西。

此代码看起来像我见过的每个示例。任何人都可以看到我做错了什么?

由于提前,

克里夫

+0

你在哪里初始化的tabBarController? – drewag 2011-03-22 02:03:14

+0

“LoginViewController”如何加载其视图?你为nib名称传递'nil',所以你必须重写'loadView'以编程方式加载视图才能工作。如果是这样,你是否在'loadView'中调用'setView:'(或者如果使用点语法来执行'self.view = whatever')? – jlehr 2011-03-22 03:00:34

+0

@jlehr如果您使用nil作为笔尖名称,它将首先尝试使用与该类名称相同的笔尖。仍然似乎是它会更好指定它,虽然 – drewag 2011-03-22 03:32:47

回答

0

HPOE这post会给你一些想法。

+0

我想在AppDelegate中做到这一点。 – clifgriffin 2011-03-22 14:23:06

+0

then code as,if(IsLoggedIn == NO) //显示登录控制器 self.window.rootViewController = self.tvc; } – KingofBliss 2011-03-23 01:28:34

+0

有趣的方法。我结束了为了完成链接而使用的方法。 :)我会在未来的修订中记住这一点。 – clifgriffin 2011-03-24 02:46:07

2

我想出了这一点:

- (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]; 
     }); 
    } 
相关问题