iphone - 关于 View Controller 中的导航 Controller

标签 iphone ios uiviewcontroller uinavigationcontroller

在 appdelagate 中,我们还有一个 UINavigationController 和 View Controller 。然后在其中我们可以使用 Root View Controller 初始化导航 Controller 。我明白为什么也需要它们。

但是,在我的引用书(iPhone SDK应用程序开发,作者:Jonathan Zdziarski)的示例代码中,所有 View Controller 类都添加了导航 Controller 作为属性,但它们似乎从未使用过。那么将它们作为 View Controller 类中的属性意味着什么?

例如

@interface XYZViewController: UIViewController
{
  UITextView *textView;
  UIButton *button;
  .....
  .....
  UINavigationController *navigationController;
}

-(void)...

.....
...
@end

还有一个问题:

所有 UIViewController 实例在导航后都可以具有“navigationItem”属性。那么这个 navigationItem 指的是什么呢?它是否引用正在导航 View Controller 的导航 Controller ?

最佳答案

UIViewController 具有由框架处理的 navigationController 属性,如果相关 View Controller 有一个属性,它会指向父 UINavigationController

查看文档以获取更多信息:

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIViewController_Class/Reference/Reference.html

同一份文档会告诉您,navigationItem 是一个 UINavigationItem 对象,它代表导航栏中的 View Controller 。您可以自定义其外观,例如标题、提示、后退按钮行为等。

也就是说,我不知道为什么你的书向 UIViewController 子类添加了 navigationController 属性。它是在 iOS 2.0 中添加的,很久以前就已经添加了...无论如何,您不需要添加它,因为它是在 UIViewController 类中提供的。

关于iphone - 关于 View Controller 中的导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7833861/

相关文章:

适用于 native 应用程序的 iPhone 模拟器/解释器(为 ARM 编译)

ios - 窥视 iOS 9 应用程序崩溃

ios - 在 viewDidLoad IOS 10 中获取内部 View 大小

iphone - 如何在 iOS 中通过函数从同一个类调用 ViewDidLoad 方法

iphone - 如何在单击 iphone 键盘的键时禁用大字母

IO 应用程序语言

ios - 在 UIViewController 上设置方向

iphone - iOS5:通过 https 进行身份验证

ios - NSFileManager 如何返回文件路径的文件夹名称

ios - 重新启动 GameViewController/GameScene