ios-Custom Navigationitem return button "Pop Back button"

Source: Internet
Author: User

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"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.