如何使UIViewController成为NavigationController堆栈的根?

时间:2011-08-30 14:27:35

标签: ios

我正在使用以下代码从appDelegate推送我的主要UIViewController:

HomeViewController *homeViewController = [[HomeViewController alloc] init];
[self.navigationController pushViewController:homeViewController animated:YES];
//self.navigationController.view = homeViewController.view;
[homeViewController release];

但是,我希望它是UINavigationController控制器堆栈的根,而目前可以移回另一个根视图控制器。 感谢

1 个答案:

答案 0 :(得分:0)

您可以使用此方法:

- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated

例如:

HomeViewController *homeViewController = [[HomeViewController alloc] init];
[self.navigationController setViewControllers:[NSArray arrayWithObject:homeViewController] animated:YES];
[homeViewController release];