让 ViewController 访问 NavigationController 的好方法?

发布于 2024-10-21 10:08:50 字数 489 浏览 0 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生漫 2024-10-28 10:08:50

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文