How to detect if view controller is being popped of from the navigation controller?

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.

Leave a Comment