Wednesday, 7 January 2015

How to check if a UIViewController is being dismissed/popped?

To know if your UIVIewController is being dismissed or popped, you can ask your UIVIewController if it is being dismissed or being moved from it’s parent UIVIewController.

- (void)viewWillDisappear:(BOOL)animated {
  [super viewWillDisappear:animated];
  if (self.isBeingDismissed || self.isMovingFromParentViewController) {
    // Handle the case of being dismissed or popped.

This has been documented in UIVIewController.h at lines 270-275 (iOS 8.1, Xcode 6.1.1).

Via StackOverflow