我正在开发一个应用程序,其中我在 AppDelegate
中使用 UINavigationController
。在启动时,我使用 UIViewController
对其进行初始化。
self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self.navigationController setNavigationBarHidden:YES];
[window addSubview:self.navigationController.view]; like this.
但是,我想将其他 UIViewControllers
添加到 UINavigatioNController
,但我知道重新初始化 UINavigationController< 不是好的做法
每次我想使用其他 UIViewControllers
。你能告诉我这样做的正常方法吗?
最佳答案
如果你确切地知道你想要你的 View Controller 堆栈是什么,那么你可以直接设置它们。
例如,假设我希望导航 Controller 上的 View 以 OverView > TableView > NewItemView 开头。我希望人们在启动应用程序后立即创建他们的第一个条目。在我的导航 Controller 中,我只需要在 -application:didFinishLaunchingWithOptions:
中执行以下操作。
NSArray *stack = [NSArray arrayWithObjects:overViewController, tableViewController, newItemViewController, nil];
navController.viewControllers = stack;
请注意,这会完全删除旧堆栈。导航 View Controller 中的任何 View Controller 都将丢失。
关于objective-c - 如何将 View Controller 添加到我的导航 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10969739/