当用TabBarController作为app的根控制器时,还需要在里面的子viewController中加入NavigationController,这种情况在appDelegate可以这样写
MainTabBarViewController *mainTabbar = [[MainTabBarViewController alloc] init];
MessagesViewController *messagesVC = [[MessagesViewController alloc] init];
UINavigationController *messagesNav = [[UINavigationController alloc] initWithRootViewController:messagesVC];
BookingsViewController *bookingsVC = [[BookingsViewController alloc] init];
UINavigationController *bookingsNav = [[UINavigationController alloc] initWithRootViewController:bookingsVC];
mainTabbar.viewControllers = @[messagesNav,bookingsNav];
self.window.rootViewController = mainTabbar;
如果有登录界面,进入后显示TabBarController,可以在登录界面写
MainTabBarViewController *mainTabbar = [[MainTabBarViewController alloc] init];
MessagesViewController *messagesVC = [[MessagesViewController alloc] init];
UINavigationController *messagesNav = [[UINavigationController alloc] initWithRootViewController:messagesVC];
BookingsViewController *bookingsVC = [[BookingsViewController alloc] init];
UINavigationController *bookingsNav = [[UINavigationController alloc] initWithRootViewController:bookingsVC];
mainTabbar.viewControllers = @[messagesNav,bookingsNav];
[self presentViewController:mainTabbar animated:YES completion:nil];
跳转用present,不能用push