Reputation: 14974
I know that you can add a custom "back" button to a UINavigationBar, but doing so removes the existing button with the tapered left side, as described in What happens when back button is pressed in navigationBar
Is there any way to keep the existing behavior and look of the back button, but also be informed when it is pressed?
Basically, I want my app to play a sound whenever any button is touched. I can do it with UITabBarController via its delegate, but the delegate for UINavgationBarController has no such functionality.
Upvotes: 3
Views: 2579
Reputation: 51374
The following are the possibilities for a View Controller to disappear.
Either case viewWillDisappear:
method will be called. Keep a boolean flag. Lets name it isAnyButtonClicked. And set isAnyButtonClicked = YES
whenever any button is clicked. And override the viewWillDisappear:
method, and play the sound if no button is clicked(ie., isAnyButtonClicked == NO
). Probably your viewWillDisappear:
would look like,
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (!isAnyButtonClicked) {
// Play sound
isAnyButtonClicked = NO;
}
}
Upvotes: 3