UINavigationController的 initWithNavigationBarClass:toolbarClass: 创建方法使用

只是看到iOS文档中关于此方法的说明,还未经过实际验证,先记录下。

关于该方法的说明如下:

Discussion
Use this initialization method if you want to use custom navigation bar or toolbar subclasses with the navigation controller. If you use this method, you are responsible for adding a root view controller before presenting the navigation controller onscreen.


在网上查询得到答复如下:


// This code assumes `MyCustomNavigationBar` is the name of your custom subclass, and that `viewController` is a UIViewController object created earlier.
// To create the containing navigation controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[MyCustomNavigationBar class] toolbarClass:[UIToolbar class]];

// To set the root view controller in the navigation controller
navigationController.viewControllers = @[viewController]


The code above informs UIKit to create a UINavigationController with navigation bars of subclass MyCustomNavigationBar.Then, it sets the root view controller to the object stored in the variable viewController.


在UINavigationController的viewControllers属性有如下说明:

The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array.

即说明在该数组中第一个添加的视图控制器即为根视图控制器(导航控制器的)。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值