今天尝试了将同一个Controller对象做为多个导航栏控制器的根控制器,结果就是只有最后子控制器的视图背景是黄色,其余的视图背景都是黑的,额不能说视图背景,由于根本就么有根控制器app
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; UITabBarController *tabBarCtr = [[UITabBarController alloc]init]; UITableViewController *tableVC = [[UITableViewController alloc]init]; tableVC.title = @"xxx"; tableVC.view.backgroundColor = [UIColor yellowColor]; for (int i = 0 ; i<4; i++) { [tabBarCtr addChildViewController:[[UINavigationController alloc]initWithRootViewController:tableVC]]; } for (UINavigationController *chileVC in [tabBarCtr childViewControllers]) { NSLog(@"%@", chileVC.viewControllers); } self.window.rootViewController = tabBarCtr; [self.window makeKeyAndVisible]; return YES; }
打印的结果code
结论:同一个控制器只能做为一个NavigationController的根控制器,如上代码中屡次赋值,不报错,只是最后设置的才有效对象