Is there a way to be notified when a ViewController is removed from a UINavigationController because the back button was pressed?
views:
80answers:
2
+2
A:
You can use viewWillDisappear:
in the view controller that is disappearing. If the other view controller needs to be notified, you can use a delegate method to notify it:
//in the disappearing view controller, class MYViewController
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
//do stuff you need to do
if ([self.delegate respondsToSelector:@selector(myViewControllerDidDisappear:)])
[self.delegate myViewControllerDidDisappear:self]; //bottom view controller is delegate
}
eman
2010-05-16 22:37:37
viewWillDisappear: also gets called if you push another view controller on top of it, not just when going back.
progrmr
2010-05-17 00:00:28
+1
A:
In conjunction with eman's method, check
[navController.viewcontrollers count]
If it is one greater than before (you need to maintain a count) then something was pushed. If it is one less, and viewWillDisappear:
was called, then the view controller was removed.
Adam Eberbach
2010-05-17 00:14:51