如何更改NavigationController的rootviewcontroller?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (18)

我有navigationController这是作为modalview呈现,其中的rootviewcontroller是说FirstViewController.At点我想将navigationController的rootviewcontroller更改为SecondViewController.What我做的是

[self.navigationController initWithRootViewController:SecondViewController];

FirstViewController是否被释放?

提问于
用户回答回答于

做任何一个

[firstViewController.navigationController setViewControllers: [NSArray arrayWithObject: secondViewController] 
                                                    animated: YES];

要么

firstViewController.navigationController.viewControllers = [NSArray arrayWithObject: secondViewController];

其中firstViewController是FirstViewController的实例,secondViewController是SecondViewController类的实例。后一种变体是setViewControllers的快捷方式:animated:without animation.

用户回答回答于
- (void) changeRootViewControllerOFNavigationControlllerAtRuntime:(UIViewController *) viewController {

     UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:viewController];
     [UIApplication sharedApplication].delegate.window.rootViewController=navController; 
}     

扫码关注云+社区