本文介绍了通过initWithRootViewController以外的方法设置UINavigationController的rootViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过initWithRootViewController
以外的方法设置UINavigationController
的rootViewController
?
How Do I set the rootViewController
of UINavigationController
by a method other than initWithRootViewController
?
我想使用initWithNavigationBarClass:toolbarClass:
为我的NavigationController交付自定义工具栏,所以我认为我不能使用initWithRootViewController
.
I want use initWithNavigationBarClass:toolbarClass:
to deliver a custom toolbar for my NavigationController, so I don't think I can use initWithRootViewController
.
推荐答案
您可以通过调用setViewControllers
来解决此问题.
You can solve this by calling 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)
这篇关于通过initWithRootViewController以外的方法设置UINavigationController的rootViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!