navigationController.navigationItem vs navigationItem(navigationController.navigationItem 与 navigationItem)
问题描述
只是好奇,为什么设置 self.navigationItem = ... 有效,但 self.navigationController.navigationItem 失败?这同样适用于 self.toolbarItems 与 self.navigationController.toobarItems.
Just curious, why setting self.navigationItem = ... works, but self.navigationController.navigationItem fails? The same applies for self.toolbarItems vs self.navigationController.toobarItems.
什么时候使用self.navigationController.navigationItem?
也许你会说,它们指向不同的东西.但是为什么 self.navigationController.navigationBarHidden = YES 导航栏是隐藏的.不是说 self.navigationController.navigationItem 指向我想要的栏吗?
Maybe you will say, they point to different things. but why self.navigationController.navigationBarHidden = YES the navigation bar is hidden. doesn't it means self.navigationController.navigationItem point to the bar i wanted?
推荐答案
类UIViewController有一个属性navigationItem.
无论是 UICollectionViewController、UITableViewController、UINavigationViewController 还是任何自定义子类,所有子类也是如此.
This is true of all the subclasses too whether it is a UICollectionViewController, UITableViewController, UINavigationViewController or any custom subclass.
当由 UINavigationController 呈现时,导航控制器将创建此属性,因此每个视图控制器都有自己的 navigationItem.如果您不从导航控制器中显示它,则 navigationItem 为 nil.
When presented by a UINavigationController the nav controller will create this property and so each view controller gets its own navigationItem. If you do not present it from a navigation controller then the navigationItem is nil.
现在,使用 UINavigationController 您很有可能将其用作您的初始视图控制器.因此,导航控制器没有被另一个导航控制器呈现,并且它的 navigationItem 属性为 nil.
Now, with a UINavigationController you are more than likely using this as your initial view controller. Therefore, the navigation controller is NOT being presented by another navigation controller and its navigationItem property is nil.
导航栏略有不同,因为这是以相反的方式管理的.
The navigation bar is slightly different as this is managed the other way around.
这篇关于navigationController.navigationItem 与 navigationItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:navigationController.navigationItem 与 navigationItem
基础教程推荐
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
