2012-06-05 48 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)。

相关问题