objective-c - 如何将 View Controller 添加到我的导航 Controller ?

标签 objective-c ios uiviewcontroller uinavigationcontroller

我正在开发一个应用程序,其中我在 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/

相关文章:

iphone - 如何调整 UIImageView 的大小?

ios - 从 UIAlertController 按钮导航到 ViewController 单击

iphone - objectForKey,iOS 中的 JSON?不工作!

iOS/苹果 watch : iPhone app network request callback blocks not triggered when app is in background

objective-c - 关于 objective-C 和 cocoa/cocoa-touch 的实现的良好知识/信息来源是什么?

ios - 有视频 : After Peek and Pop (3D Touch) background keeps scrolling

iphone - NSMutableData SetLength错误

ios - 如何为导航 Controller 提供自定义 UIViewControllerAnimatedTransitioning 和使用默认 UIViewControllerInteractiveTransitioning

objective-c - 在 NSBundle 中使用 ConnectionKit 框架

ios - 如何在 AFNetworking 2.0 中设置请求超时和缓存策略?