ios - 通过 initWithRootViewController 以外的方法设置 UINavigationController 的 rootViewController

标签 ios uinavigationcontroller uitoolbar iphone-5

如何通过 initWithRootViewController 以外的方法设置 UINavigationControllerrootViewController

我想使用 initWithNavigationBarClass:toolbarClass: 为我的 NavigationController 提供自定义工具栏,所以我认为我不能使用 initWithRootViewController

最佳答案

您可以通过调用 setViewControllers 来解决这个问题。

像这样:

UINavigationController *navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[MyNavigationBar class] toolbarClass:[UIToolbar class]];

[navigationController setViewControllers:@[yourRootViewController] animated:NO];

快速版本:

let navigationController = UINavigationController(navigationBarClass: MyNavigationBar.self, toolbarClass: UIToolbar.self)

navigationController.setViewControllers([yourRootViewController], animated: false)

关于ios - 通过 initWithRootViewController 以外的方法设置 UINavigationController 的 rootViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16215034/

相关文章:

ios - 模态视图 Controller - 如何显示和关闭

swift - 未触发刷新控件目标操作

iphone - 他们是怎么做到的?...避免无聊、千篇一律的标准 iPhone 应用程序

iphone - 如何将 UILabel 放在 UIToolbar 之上?

iphone - UIToolBar 中的 UISegmentedControl

ios - 在 Objective C 中打印一个变量

iphone - UIImagePickerController 横向录制视频

iphone - 将 UIBarButtonItem 添加到 navigationItem.titleView?

c# - NavigationController 颜色和左键

ios - 为什么DispatchGroup会干扰主队列?