The solution is simple. You have to subclass your navigationController’s popViewControllerAnimated:(BOOL)animated. So create a custom navigationController:
customNavigationController.h
#import
@interface customNavigationController : UINavigationController {}
@end
And a custom “popViewControllerAnimated:(BOOL)animated”, this popViewControllerAnimated-function uses the “UIViewAnimationTransitionCurlDown” when popping from a SettingsTableView.
customNavigationController.m
#import “customNavigationController.h”
#import “SettingsTableController.h”
@implementation customNavigationController
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
if([[self.viewControllers lastObject] class] == [SettingsTableController class]){
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 1.00];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:self.view cache:NO];
UIViewController *viewController = [super popViewControllerAnimated:NO];
[UIView commitAnimations];
return viewController;
} else {
return [super popViewControllerAnimated:animated];
}
}
@end
Use your custom navigationController in your appDelegate:
customNavigationController *navigationController =
[[customNavigationController alloc]
initWithRootViewController:rootView];
Another Method
To Jules or anyone else who happens upon this page: I also needed a “are you sure you want to quit?” on the back button for my app. Here’s how I implemented it. Tricky but possible!
Turns out if you implement the UINavigationBarDelegate in the CustomNavigationController, you can make use of the shouldPopItem method:
—————————————————-
CustomNavigationController.h :
#import
@interface CustomNavigationController : UINavigationController {
BOOL alertViewClicked;
BOOL regularPop;
}
@end
—————————————————-
CustomNavigationController.m :
#import “CustomNavigationController.h”
#import “SettingsTableController.h”
@implementation CustomNavigationController
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {
if (regularPop) {
regularPop = FALSE;
return YES;
}
if (alertViewClicked) {
alertViewClicked = FALSE;
return YES;
}
if ([self.topViewController isMemberOfClass:[SettingsTableViewController class]]) {
UIAlertView * exitAlert = [[[UIAlertView alloc] initWithTitle:@”Are you sure you want to quit?”
message:nil delegate:self cancelButtonTitle:@”Cancel” otherButtonTitles:@”Yes”, nil] autorelease];
[exitAlert show];
return NO;
}
else {
regularPop = TRUE;
[self popViewControllerAnimated:YES];
return NO;
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
//Cancel button
}
else if (buttonIndex == 1) {
//Yes button
alertViewClicked = TRUE;
[self popViewControllerAnimated:YES];
}
}
@end
Incoming search terms:
- custom action back button ios
- uinavigationcontroller custom back action
- create own button uiviewcontroller
- uiviewcontroller back button cancel
- uinavigationitem back button clicked
- uinavigationcontroller back button custom class
- uinavigationcontroller back button action
- uinavigationcontroller action back button
- function to back uinavigationcontroller and refresh
- custom navigationbar shouldpopitem