通过initWithRootViewController以外的方法设置UINavigationController的rootViewController [英] Set rootViewController of UINavigationController by method other than initWithRootViewController

查看:484
本文介绍了通过initWithRootViewController以外的方法设置UINavigationController的rootViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆