hi,
Is there a way to find out whether the back button (Navigation bar) is clicked for a particular view ? if yes how ?
hi,
Is there a way to find out whether the back button (Navigation bar) is clicked for a particular view ? if yes how ?
First of all, I didn't try this myself. I don't know of a way to intercept the click on the button. What "might" work is the following: There is the UINavigationBarDelegate, which contains the navigationBar:shouldPopItem: event. This event is called before a navigationItem is removed from the stack of your navigationBar, so if you handle this event, you might be able to do whatever you want to archive.
"handling events before" suggests you want to clean up or save state before the user leaves the view. In that case, I'd use viewWillDisappear: or viewDidDisappear:. If you need to distinguish between navigating back and navigating "forwards" (e.g. pushing a VC, or presenting a modal VC), you might be able to do something like:
-(void)viewDidDisappear:(BOOL)animated
{
if (!self.parentViewController)
{
// back button pressed/modal VC dismissed/etc, hopefully
}
}
I haven't tested this, but my understanding is that "Will"-methods are called before the VC hierarchy is changed, and "Did"-methods are called afterwards.
If you're saving state, you should also handle UIApplicationWillEnterBackgroundNotification.