objective-c - 在 iOS 系统中,能否获取到当前显示的控制器?
阿神
阿神 2017-04-18 09:29:14
0
2
621

在 iOS 系统中,不通过提前获取并存储数据的方案。能否获取到当前显示的控制器

需要处理的一些情况
  • 自定义的控制器

  • UITabBarController

  • present

问题说明,通过runtime替换-view***Appear:相关方法的实现,可以实现本需求。但是这种情况,需要开发者在某处保存当前显示的控制器。所以,该方案不满足需求。

统一回复:

self.navigationController.viewControllers.lastObject
这类方案只能在控制器中获取控制器所在navigationController的最后一个控制器,它和当前显示的控制器不恒等。
比如tab+nav架构中,当前显示的是第二tab,在第一个tab的nav的某个控制器中执行该方法,并不能获取当前显示的控制器

阿神
阿神

闭关修行中......

reply all(2)
洪涛

If there is a navigation bar, you can find self.navigationController.viewControllers.lastObject through the controller stack saved in the navigation bar. I don’t quite understand what is written there about some situations you need to handle...

左手右手慢动作

You can get the controller you are on through navigation and jump back accordingly

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!