iOS:如果不使用 UINavigationController,以编程方式查看导航堆栈中的视图控制器? [英] iOS: programmatically see view controllers in navigation stack if not using a UINavigationController?

查看:23
本文介绍了iOS:如果不使用 UINavigationController,以编程方式查看导航堆栈中的视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以查看导航堆栈中的视图控制器?Swift 和 iOS 新手,只想确保导航正常进行,并且视图控制器不会无意中堆积起来.

Is it possible to see which view controllers are in the navigation stack? New to Swift and iOS and just want to make sure navigation is happening properly and view controllers aren't stacking up inadvertently.

澄清一下,您似乎可以在 UINavigationController 中使用 viewControllers 属性,但出于学习目的,我们没有使用导航控制器并通过退出segue手动进行导航.

To clarify, it seems like you can use the viewControllers property in a UINavigationController, but for learning purposes, we're not using a navigation controller and doing the navigation manually through exit segues.

如果不使用 UINavigationController,你能以编程方式打印出视图控制器层次结构吗?

Can you programmatically print out the view controller hierarchy if not using a UINavigationController?

推荐答案

是否可以查看导航堆栈中的视图控制器?...如果不使用 UINavigationController,您能否以编程方式打印出视图层次结构?

Is it possible to see which view controllers are in the navigation stack?...Can you programmatically print out the view hierarchy if not using a UINavigationController?

你在这里谈论的是两个完全不同的事情.视图和视图控制器不是同一种对象.它们都倾向于用于像它们一样的对象的有向图,但是这两种对象的图是完全不同的.也就是说,导航控制器是一种视图控制器,它保存其他视图控制器的列表,并且(单独)视图保存它包含的视图数组.最后,大多数视图控制器管理一个通常包含其他视图的视图.

You're talking about two complete different things here. Views and view controllers are not the same kind of object. They do both tend to be used in directed graphs of objects like themselves, but the graphs of those two kinds of objects are quite different. That is, a navigation controller is a kind of view controller that keeps a list of other view controllers, and (separately) a view keeps an array of the views that it contains. Finally most view controllers manage a single view that usually contains other views.

查看视图层次结构的一种简单方法是在您的一个视图控制器中的某行上设置断点,并使用调试器po [self.view recursiveDescription],它将打印 (在调试器中)该视图控制器管理的视图和子视图的描述.

An easy way to see the hierarchy of views is to set a breakpoint on some line in one of your view controllers and use the debugger to po [self.view recursiveDescription], which will print (in the debugger) a description of the view and subviews that that view controller manages.

一种更简单的方法是使用 Xcode 的漂亮视图调试器,它为您提供了一个分层视图,您可以在 3D 中进行检查:

An even easier way to do it is to use Xcode's nifty view debugger, which gives you a layered view that you can examine in 3D:

该检查器的图标看起来像一个矩形叠加在另一个矩形上:

The icon for that inspector looks like one rectangle on top of another:

您当然可以打印出您的代码可以访问的任何对象图,但从您的评论看来,您必须编写一个方法才能做到这一点.如果您不使用导航控制器,则不会打印出导航堆栈".当然,您可以实现自己版本的导航堆栈,但之后您需要提供检查它的方法.

You can certainly print out any graph of objects that your code can access, but from your comment it sounds like you'll have to write a method to do it. If you're not using a navigation controller, then there is no "navigation stack" to print out. You can implement your own version of a navigation stack, of course, but then it's up to you to provide a way to inspect it.

这篇关于iOS:如果不使用 UINavigationController,以编程方式查看导航堆栈中的视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆