ios - adding a custom back button now causes crash when going to RootViewController -
I am using a standard navigation controller in my app, but recently I had to make such changes, which only It should be done only when the user presses the back button on the navigation bar. So to catch it, I'm trying to create a custom back button to capture my selector.
Now the NAV bar is already a back button, so basically it is basically trying to overwrite / change it. . I'm not doing anything special, just set it to allocate it and navigation items
UIBarButtonItem * backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle: @ "back" style: UIBarButtonItemStylePlain target : Self-action: @selector (backButtonClicked)]; [Self. Navigation Itam Settlefatt Barbarton Eatam: Backburbetonium];
The problem is after a few times back (it's somewhat deep in the screen navigation), when I'm backing up on the root interpreter, I get an exception. I am guessing because IM is to add a back button when there is already a back button present and somehow navigation is coming out of oak, but I do not know what to change.
UINavigationController
is not a very good idea in the back button instead of the usual me think, because of unwanted behavior Kkk
if you need before it becomes visible again off screen to take some action, you just ViewWillDisappear
in your required Can implement the functionality.
If you want to completely change the back button, then you should take a different approach:
Write Category on UIViewController
something like,:
UIViewController + BackButton.h
@interface UIViewController (BackButton) - setBackButton (void); - (zero) donePressBackButton; @end
UIViewController + BackButton.m
@implementation UIViewController (Kstmbakbtn) - (minus) Setbakbtn {UIBarButtonItem * backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle: @ "back" style: UIBarButtonItemStylePlain goal: self action: @selector (GoBack)]; [Self. Navigation Itam Settlefatt Barbarton Eatam: Backburbetonium]; } - (zero) back {{self. Navigation Controller PopWebControllerUnited: Yes]; If ([the answer is for the cockroach: @selector (dpresspack button)] [[The self-perback button]; }} @end
In this way, you easily set up your custom controller in the viewDidLoad
in your view controller and the method didPressBackButton
to do your custom operation
#import UIViewController + BackButton.h - (zero) viewDidoadload {[Super Viewedload]; [Self setback button]; } - (zero) didPressBackButton {// your code here}
Comments
Post a Comment