在 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
。
查看文档以获取更多信息:
同一份文档会告诉您,navigationItem
是一个 UINavigationItem
对象,它代表导航栏中的 View Controller 。您可以自定义其外观,例如标题、提示、后退按钮行为等。
也就是说,我不知道为什么你的书向 UIViewController
子类添加了 navigationController
属性。它是在 iOS 2.0 中添加的,很久以前就已经添加了...无论如何,您不需要添加它,因为它是在 UIViewController
类中提供的。
关于iphone - 关于 View Controller 中的导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7833861/