我有一个标签栏应用程序。 这是启动代码
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
self.tabBarController=[[UITabBarController alloc] init];
StartViewController *startViewController=[[StartViewController alloc] initWithNibName:@"StartViewController" bundle:nil];
NavRootViewController *navRootViewController=[[NavRootViewController alloc] initWithNavControllerWithSubViewController:startViewController];
HelpViewController *helpViewController=[[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle:nil];
SettingsViewController *settingsViewController=[[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
AboutUsViewController *aboutUsViewController=[[AboutUsViewController alloc] initWithNibName:@"AboutUsViewController" bundle:nil];
[self.tabBarController setViewControllers:[NSArray arrayWithObjects: navRootViewController, helpViewController, settingsViewController, aboutUsViewController, nil]];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController=self.tabBarController;
使用4个标签栏标签启动了应用程序。 用户在第一个选项卡的导航控制器的根视图控制器中按下开始按钮后调用此操作
-(IBAction)startPressed:(id)sender
{
NSLog(@"startPressed: called");
RootViewController *vController=[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
[self.navigationController pushViewController:vController animated:YES];
}
这很好但我需要为RootViewController
隐藏标签栏
属性hidesBottomBarWhenPushed
不起作用。
请帮帮我,怎么办呢?
答案 0 :(得分:6)
我希望这会对你有所帮助:
- (void)viewWillAppear: (BOOL)animated
{
self.hidesBottomBarWhenPushed = YES;
}
答案 1 :(得分:1)
如果您不希望主视图显示标签栏,则不应将其推到导航控制器上。执行此操作会导致应用程序假定此新控制器是导航层次结构的一部分。可能最好的解决方案是在RootViewController上启动应用程序,然后以模态方式显示导航控制器。完成导航控制器后,让它自己调用dismissModalViewController
。
答案 2 :(得分:1)
是的,你必须在窗口上添加模态视图而不是在tabBar的viewcontroller上。
尝试类似的东西..制作AppDelegate的对象,如:
AppDelegate *appDelegate=[[UIApplication sharedApplication]delegate];
然后在下一行添加
[appDelegate.window.rootviewcontroller.view presentModalViewController:vController animated:YES];
或在tabBar的firstviewcontroller的viewDidAppear中添加代码[self presentModalViewController:vController animated:YES]
。
你做了什么来解决问题?我也想知道。
答案 3 :(得分:1)
使用此代码解决:
-(IBAction)startPressed:(id)sender
{
NSLog(@"startPressed: called");
RootViewController *vController=[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
UINavigationController *navController=[[UINavigationController alloc] initWithRootViewController:vController];
[vController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[((AppDelegate *)[UIApplication sharedApplication].delegate).tabBarController presentModalViewController:navController animated:YES];
}
感谢@iPhone开发人员
答案 4 :(得分:1)
UIViewController *nextViewController = [[UIViewController alloc] initWithNibName:@"NextViewController" bundle:[NSBundle mainBundle]];
// hide UITabbarController
nextViewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:nextViewController animated:YES];
[nextViewController release];