2012-06-05 84 views
0

我在Xcode 4.3中有一個選項卡欄應用程序,我試圖在顯示tabbar之前插入登錄屏幕。如果presentModalViewController具有animated:YES,則應用程序可以正常工作,但如果它沒有動畫,則視圖不顯示。選項卡式應用程序不會顯示登錄視圖

@synthesize window = _window; 

@synthesize tabBarController = _tabBarController; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; 
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 

    self.tabBarController = [[UITabBarController alloc] init]; 
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil]; 
    self.window.rootViewController = self.tabBarController; 

    LogInViewController *logViewController = [[LogInViewController alloc] initWithNibName:@"LogInViewController" bundle:nil]; 
    [self.window addSubview:_tabBarController.view]; 

    [self.tabBarController presentModalViewController:logViewController animated:YES]; 
    //This wont work 
    //[self.tabBarController presentModalViewController:logViewController animated:NO]; 

    [self.window makeKeyAndVisible]; 
    return YES; 

} 

-(void)loginDone{ 

    NSLog(@"back to the app delegate"); 
    [self.tabBarController dismissModalViewControllerAnimated:YES]; 


} 
  1. 這是做正確的方式?
  2. 爲什麼不能使用代碼animated:NO
  3. 我也得到這個在輸出Unbalanced calls to begin/end appearance transitions for <UITabBarController: 0x689d350>

回答

1

首先,在您的視圖控制器設置之前移動[self.window makeKeyAndVisible];

此外,您應該在視圖控制器的viewWillAppear:方法中首先顯示模態視圖控制器,以確保您的應用視圖層次結構在呈現登錄屏幕之前已完全初始化。

1

不要這樣做:

[self.window addSubview:_tabBarController.view]; 

這樣做:

self.window.rootViewController = _tabBarController; 

這將使tabBarController在屏幕上。但這不完全是你想要的...我的建議是:

1)首先把logViewControllerrootViewController正如我在上面給你看。

2)一旦你得到你想要的(登錄成功),只需告訴AppDelegate切換rootViewController。這可以通過委派或通知完成。另外,Toastor間接指出,你應該從UIViewController開始presentViewController,他們實際啓動它(而不是從AppDelegate)。

相關問題