本文介绍了如何检测是否从导航控制器中弹出了视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 当我从导航控制器弹出顶视图控制器时,我当前需要实现一些代码。有没有办法检测视图控制器何时从导航控制器堆栈弹出?I currently need to implement some code when the top view controller is being popped off from my navigation controller. Is there a way to detect when the view controller is being popped off the navigation controller stack?我想尽可能远离使用 viewWillDisappear 或 viewDidDisappear 因为我在我的项目中使用 splitview ,并且在主视图中选择另一行也会触发 viewWillDisappear / viewDidDisappear methods。As much as possible I want to stay away from using viewWillDisappear or viewDidDisappear because I'm using a splitview in my project, and selecting a different row in the master view will also trigger the viewWillDisappear/viewDidDisappear methods.推荐答案你可以使用视图控制器的 isMovingFromParentViewController 属性检测是否正在弹出视图,如下所示:You can detect whether a view is being popped using the isMovingFromParentViewController property for a view controller as shown below:- (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; if ([self isMovingFromParentViewController]) { NSLog(@"View controller was popped"); } else { NSLog(@"New view controller was pushed"); }}返回一个布尔值,指示视图控制器在中从父项中删除的过程。Returns a Boolean value that indicates that the view controller is in the process of being removed from its parent. 这篇关于如何检测是否从导航控制器中弹出了视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!