如何检测是否从导航控制器弹出视图控制器?

How to detect if view controller is being popped of from the navigation controller?(如何检测是否从导航控制器弹出视图控制器?)
本文介绍了如何检测是否从导航控制器弹出视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当顶视图控制器从我的导航控制器中弹出时,我目前需要实现一些代码.有没有办法检测视图控制器何时从导航控制器堆栈中弹出?

我想尽可能避免使用 viewWillDisappearviewDidDisappear 因为我在我的项目中使用了 splitview,并且在主视图中选择不同的行也会触发 viewWillDisappear/viewDidDisappear 方法.

解决方案

您可以使用视图控制器的 isMovingFromParentViewController 属性来检测视图是否正在弹出,如下所示:

- (void)viewWillDisappear:(BOOL)animated{[超级viewWillDisappear:动画];if ([self isMovingFromParentViewController]){NSLog(@"视图控制器被弹出");}别的{NSLog(@"新的视图控制器被推送");}}

<块引用>

isMovingFromParentViewController

返回一个布尔值,表示视图控制器在从父级中移除的过程.

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?

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.

解决方案

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");
    }
}

isMovingFromParentViewController

Returns a Boolean value that indicates that the view controller is in the process of being removed from its parent.

这篇关于如何检测是否从导航控制器弹出视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)