让 ViewController 访问 NavigationController 的好方法?
我是 iPhone 编程新手,我正在编写一个顶部有一个导航栏和几个连续的视图控制器的应用程序。
我想知道:我应该如何设计这样的东西?显然 ViewController 需要访问 NavigationController,但是如何访问呢?我创建了一个 UINavManagedViewController 来存储对导航控制器的引用,并且所有视图控制器都派生自该类。
@interface UINavManagedViewController : UIViewController {
UIManagingNavigationController *navManager;
}
@property (nonatomic, retain) UIManagingNavigationController *navManager;
@end
然而,由于这显然是所有程序员都会遇到的事情,所以我想知道处理这种设置的默认方法。我的初级 iPhone 编程书没有处理这种情况。
I am new to iPhone programming and I am programming a app that has a NavigationBar on top, and several successive ViewControllers.
I was wondering: how should I design such a thing? Clearly the ViewControllers need to have access to the NavigationController, but how? I have created a UINavManagedViewController that stores a reference to the navigationcontroller, and all viewcontrollers derive from that class.
@interface UINavManagedViewController : UIViewController {
UIManagingNavigationController *navManager;
}
@property (nonatomic, retain) UIManagingNavigationController *navManager;
@end
However, since this is clearly a thing that all programmers encounter, I was wondering about the default way to handle such a setup. My beginner iPhone programming book didn't handle such cases.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 UIViewController 类参考。所有 UIViewController 都已具有一个 navigationController 属性,该属性提供对其父导航控制器(如果存在)的引用。
Take a look at the UIViewController class reference. All UIViewControllers already have a
navigationController
property which provides a reference to their parent navigation controller (if one exists).