NavigationController问题

今天尝试了将同一个Controller对象作为多个导航栏控制器的根控制器,结果就是只有最后子控制器的视图背景是黄色,其他的视图背景都是黑的,额不能说视图背景,因为根本就么有根控制器

- (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;
}

打印的结果

 NavigationController问题_第1张图片


结论:同一个控制器只能作为一个NavigationController的根控制器,如上代码中多次赋值,不报错,只是最后设置的才有效

你可能感兴趣的:(NavigationController问题)