我在Xcode 4.3中有一个标签栏应用程序,我试图在显示标签栏之前插入登录屏幕。如果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];
}
animated:NO
?Unbalanced calls to begin/end appearance transitions for <UITabBarController: 0x689d350>
上得到了这个。答案 0 :(得分:1)
首先,在视图控制器设置之前移动[self.window makeKeyAndVisible];
。
此外,您应该首先在视图控制器的viewWillAppear:
方法中呈现模态视图控制器,以确保在显示登录屏幕之前已完全初始化您的应用视图层次结构。
答案 1 :(得分:1)
不要这样做:
[self.window addSubview:_tabBarController.view];
这样做:
self.window.rootViewController = _tabBarController;
这会将tabBarController
放在屏幕上。但那不是你想要的......我的建议是:
1)首先让logViewController
有rootViewController
,如上所示。
2)一旦你得到了你想要的东西(登录成功),就告诉AppDelegate切换rootViewController
。这可以通过委托或通知来完成。
另外,正如Toastor间接指出的那样,你应该从实际启动它的UIViewController
启动presentViewController(而不是从AppDelegate启动)。