Getting the top most UIViewController(获取最顶层的 UIViewController)
问题描述
如果我在 UINavigationController 上推送视图控制器和/或呈现模式视图控制器,我如何找出最顶部的 UIViewController 是什么?或者就我而言,我想知道某个 UITableViewController 是否是最顶层的.
If I push view controllers and/or present modal view controllers on a UINavigationController, how can I find out what is the top most UIViewController? Or in my case, I want to know if a certain UITableViewController is the top most or not.
我尝试使用:
self.navigationController.topViewController == self
...但这不起作用.我猜它失败了,因为我在它上面展示了模态视图控制器,并且 topViewController 只跟踪在 UINavigationController 上推送了哪些视图(如反对那些以模态形式呈现的).
... but this doesn't work. I'm guessing that it's failing because I'm presenting modal view controllers on top of it and that the topViewController only keeps track of which views were pushed on the UINavigationController (as opposed to those that were presented modally).
推荐答案
你想要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.
这篇关于获取最顶层的 UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取最顶层的 UIViewController
基础教程推荐
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
