如何访问 UINavigationController 中的堆栈

发布于 2024-11-17 10:23:05 字数 449 浏览 2 评论 0原文

视图控制器

当前的视图控制器 导航堆栈。

@property(nonatomic, copy) NSArray * viewControllers

讨论

根视图控制器位于索引 0 处 数组,后视图控制器位于 索引n-2,顶层控制器是 在索引 n-1 处,其中 n 是 数组中的项目。

分配新的视图数组 该属性的控制器是 相当于调用 setViewControllers:animated: 方法 将动画参数设置为 NO。

我很困惑如何访问堆栈我在导航控制器中有三个视图 - 根视图控制器、sti 测试位置、sti 地图。

我如何访问堆栈?

viewControllers

The view controllers currently on the
navigation stack.

@property(nonatomic, copy) NSArray * viewControllers

Discussion

The root view controller is at index 0 in the
array, the back view controller is at
index n-2, and the top controller is
at index n-1, where n is the number of
items in the array.

Assigning a new array of view
controllers to this property is
equivalent to calling the
setViewControllers:animated: method
with the animated parameter set to NO.

I am confused how to access the the stack I have three views in the navigation controller – root view controller, sti testing location, sti map.

How can I access the stack?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

不知所踪 2024-11-24 10:23:05

正如您上面所述,UINavigationControllers 有一个名为 viewControllers 的属性。由于这是一个视图控制器数组,因此引用此层次结构中的特定视图控制器与访问数组中的任何其他对象没有什么不同。

UIViewController *theControllerYouWant = [self.navigationController.viewControllers objectAtIndex:(theIndexOfYourViewController)];

此外,请查看导航控制器 iOS 开发者库中的文章,特别是名为“修改导航堆栈”的部分。

UINavigationControllers have a property called viewControllers as you have stated above. Since this is an array of View Controllers, referencing a specific view controller in this hierarchy is no different than accessing any other object in an array.

UIViewController *theControllerYouWant = [self.navigationController.viewControllers objectAtIndex:(theIndexOfYourViewController)];

In addition check out the Navigation Controllers article in the iOS Developer Library, specifically the section called 'Modifying the Navigation Stack'.

极度宠爱 2024-11-24 10:23:05

假设您的导航控制器具有三个视图控制器,您应该能够使用 self.navigationController 从三个视图控制器中的任何一个访问导航控制器。

因此,如果您想获取堆栈中的第二个视图控制器,您应该

UIViewController * viewController = [self.navigationController.viewControllers objectAtIndex:1];

这样做 - 假设导航控制器上至少有两个视图控制器。

Assuming you meant that your navigation controller has three view controllers, you should be able to access the navigation controller from any of three view controllers using self.navigationController.

So if you want to get the second view controller in the stack, you should do –

UIViewController * viewController = [self.navigationController.viewControllers objectAtIndex:1];

This is assuming that there are at least two view controllers on the navigation controller.

灵芸 2024-11-24 10:23:05

viewControllers 属性返回的数组是堆栈。它们的排列顺序与显示的顺序相同。索引 0 处的控制器是您开始使用的控制器。您当前正在查看的控制器是索引最高的。由于索引是从零开始计数的,因此最后一项索引将为计数 (n)-1。

现在你在帖子中说“观点”。视图和视图控制器之间存在差异。如果您谈论的是同时可见的多个部分,那么您谈论的是视图而不是视图控制器。导航控制器用于处理多个视图控制器。如果您正在处理视图,而不是想要访问当前视图控制器视图的子视图 myViewController.view.subviews 它们以类似的方式对自己进行排序。

The array returned by the viewControllers property is the stack. They are ordered in the same sequence that they were shown. the controller at index 0 is the controller you started with. The controller you are currently looking at is the highest index. Since indexes are counted from zero the last item index will be the count (n)-1.

Now you say "views" in your post. There is a difference between views and view controllers. If you are talking about multiple pieces that are all visible at the same time then you are talking about views not view controllers. The Navigation Controller is for handling multiple view controllers. If you are dealing with views than you want to access the subviews of the current view controller's view myViewController.view.subviews They order themselves in a similar way.

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