0

我有一个标签栏应用程序。这是启动代码

    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不起作用。请帮帮我,怎么办?

4

5 回答 5

6

我希望这可以帮助你:

- (void)viewWillAppear: (BOOL)animated 
{ 
    self.hidesBottomBarWhenPushed = YES; 
}
于 2012-06-27T05:36:27.893 回答
1

如果您不希望主视图显示标签栏,则不应将其推送到导航控制器上。这样做会导致应用程序假定这个新控制器是导航层次结构的一部分。最好的解决方案可能是在 RootViewController 上启动您的应用程序,然后以模态方式呈现导航控制器。完成导航控制器后,让它dismissModalViewController自行调用。

于 2012-06-26T13:24:32.597 回答
1

是的,你必须在窗口而不是 tabBar 的 viewcontroller 上添加 modalview。尝试类似.. 制作 AppDelegate 的对象,例如: AppDelegate *appDelegate=[[UIApplication sharedApplication]delegate]; 然后在下一行添加

[appDelegate.window.rootviewcontroller.view presentModalViewController:vController animated:YES];

或者将您的代码添加[self presentModalViewController:vController animated:YES]到 tabBar 的 firstviewcontroller 的 viewDidAppear 中。

你做了什么来解决这个问题?我也想知道。

于 2012-06-27T05:14:33.090 回答
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 开发者

于 2012-07-18T13:28:57.510 回答
1
UIViewController *nextViewController = [[UIViewController alloc] initWithNibName:@"NextViewController" bundle:[NSBundle mainBundle]];

// hide UITabbarController
nextViewController.hidesBottomBarWhenPushed = YES;

[self.navigationController pushViewController:nextViewController animated:YES];
[nextViewController release];
于 2016-09-07T02:32:58.433 回答