我正在创建一个标签式iPhone应用程序。当应用程序启动时,如果用户未登录,则应该在标签栏控制器的顶部显示模态视图(因此看起来这是第一个屏幕)。登录后,模态视图会滑开以显示其后面的标签栏控制器。
不幸的是,当我从应用程序委托中调用[self.tabBarController presentViewController:self.loginViewController animated:NO completion:NULL]
时,我仍然可以看到屏幕底部的选项卡。我需要它们。
具有讽刺意味的是,在搜索解决方案时,我发现大多数人都遇到了反问题。
我注意到如果我不将我的窗口的rootViewController设置为UITabBarController,只将其视图作为窗口的子视图插入,那么它按预期工作,但Xcode抱怨缺乏rootViewController。这是怎么回事?
我的应用程序委托的-application:didFinishLaunchingWithOptions:
方法如下所示。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self registerDefaults];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = @[
[self makeSellingListingsController],
[[[UIViewController alloc] init] autorelease], // stub
[[[UIViewController alloc] init] autorelease], // stub
[[[UIViewController alloc] init] autorelease] // stub
];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.rootViewController = self.tabBarController;
[self.window addSubview:self.tabBarController.view];
[self presentLogin]; // this doesn't cover the tabs, but it should
[self.window makeKeyAndVisible];
return YES;
}
- (void)presentLogin
{
[self.tabBarController presentViewController:[[[FLLoginViewController alloc]
initWithNibName:@"FLLoginViewController"
bundle:[NSBundle mainBundle]] autorelease]
animated:NO
completion:NULL];
}
答案 0 :(得分:0)
不要从标签栏控制器中显示它,而是从第一个选项卡中的根控制器,在其viewDidAppear方法中显示它。如果将NO传递给动画参数,则模态屏幕将是您启动应用程序时看到的第一个内容。