objective-c - 获取最顶层的 UIViewController

标签 objective-c cocoa-touch uiviewcontroller uinavigationcontroller

如果我在 UINavigationController 上推送 View Controller 和/或呈现模态视图 Controller ,我如何找出最顶部的 UIViewController 是什么?或者就我而言,我想知道某个 UITableViewController 是否是最顶层的。

我尝试使用:

self.navigationController.topViewController == self

...但这不起作用。我猜它失败了,因为我在它上面展示了模态视图 Controller ,并且 topViewController 只跟踪在 UINavigationController 上推送了哪些 View (如反对那些以模态形式呈现的)。

最佳答案

你想要visibleViewController:

The currently visible view can belong either to the view controller at the top of the navigation stack or to a view controller that was presented modally.

关于objective-c - 获取最顶层的 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4067692/

相关文章:

ios - 如何使用 Objective-C 初始化嵌套的 Node.js 模式

objective-c - 从头开始重新实现 NSObject

objective-c - 在 UIScrollview 中设置 size 属性

iphone - 边界和框架 : how do I display part of an UIImage

ios - 自动布局中的比例距离约束

objective-c - 如果组合框动态添加了新的表格行,那么当 NSComboBox 选择发生更改时,我如何收到通知?

ios - 使用 Hpple 在 Xcode 中解析 xml

ios - 如何在WatchKit中获取 watch 电池

ios - 在同一容器 View 中从一个 View Controller 切换到另一个 View Controller

function - Swift,与方法名相同的变量