When using NAVIGATIONVC, the return button sometimes do not want to use the system, here with the method of inheritance to replace the button, but also can realize the system's right slip back, very simple;
1. Create a base class Basepopviewcontroller
Create a Basepopviewcontroller:uiviewcontroller to replace the system return button base class;
Basepopviewcontroller.m
#import "BasePopViewController.h"@interfaceBasepopviewcontroller ()@end@implementationBasepopviewcontroller- (void) viewdidload {[Super viewdidload]; [Self Setnavigationitembackbutton]; Self.navigationController.interactivePopGestureRecognizer.Delegate= (ID) self;}- (void) Viewdidappear: (BOOL) animated {[Super viewdidappear:animated]; if(Self.navigationController.viewControllers.count >1) {self.navigationController.interactivePopGestureRecognizer.enabled=YES; }Else{self.navigationController.interactivePopGestureRecognizer.enabled=NO; }}/** Custom status bar*/- (void) setnavigationitembackbutton{if(Self.navigationController.viewControllers.count >1) {Uibarbuttonitem*back = [[Uibarbuttonitem alloc]initwithimage:[uiimage imagenamed:@"Back_off"] Style:uibarbuttonitemstyleplain target:self action: @selector (popbackbuttonaction)]; Self.navigationItem.leftBarButtonItems=@[back]; }}/** Return button event*/- (void) popbackbuttonaction {[Self.navigationcontroller popviewcontrolleranimated:yes];}#pragmaMark-Below is the set status bar color, can be ignored-(uistatusbarstyle) preferredstatusbarstyle{///here set the white returnuistatusbarstylelightcontent;}-(BOOL) prefersstatusbarhidden{returnNO;}@end
2. References
When you need to replace the system's return button, the new VC inherits Basepopviewcontroller, if you want to get the Click Back button event in the new VC, rewrite the Popbackbuttonaction event in the new VC.
ios-Custom Navigationitem return button "Pop Back button"