Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if view that appears was pushed or came from back button in navigation bar

Is there a way to tell if a new controller came from a navigation back button or was pushed onto the stack? Id like to reload data only for pushing on the navigation stack, not on a back button press.

like image 560
Mike Flynn Avatar asked Dec 30 '13 23:12

Mike Flynn


2 Answers

As of iOS 5.0 you can do this:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    if (self.isBeingPresented || self.isMovingToParentViewController) {
        // "self" is being shown for the 1st time, not because of a "back" button.
    }
}
like image 164
rmaddy Avatar answered Nov 16 '22 02:11

rmaddy


If your push also includes instantiating the view controller, put your push-only logic in viewDidLoad. It will not be called on back because it has already been loaded.

like image 1
coneybeare Avatar answered Nov 16 '22 02:11

coneybeare