UINavigationController etc
UINavigationController hook Event
We can use UINavigationControllerDelegate.
UIViewController.h
@interface NavigationUIViewController : UIViewController<UINavigationControllerDelegate>
@end
UIViewController.m
#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
// Before navigation
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
// After navigation
}
Prevent swipe back
UIViewController.h
@interface NavigationUIViewController : UIViewController<UINavigationControllerDelegate> @end
UIViewController.m
#pragma mark - UINavigationControllerDelegate - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { // Before navigation } - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { // After navigation }
Prevent swipe back
Use interactivePopGestureRecognizer.enabled of UINavigationController
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
We should add this to – (void)viewDidAppear:(BOOL)animated for iPad.
In iPhone, viewDidLoad works, but not in iPad.
Use UINavigationController in RootController by code
AppDelegate.m
UIViewController *controller = [[UIViewController alloc] init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controller]; self.window.rootViewController = nav;