NavigationItem.BackButtonItem is null ...?

I moved my View to the NavigationController stack, I am in ViewLoaded, and I found that NavigationItem.BackBarButtonItem is null. Why is this? How can I either disable it (temporarily, and I would prefer not to hide it in this particular case), and how could I consider renaming what it shows?

+4
source share
3 answers

As @Andrew said, you can use

self.navigationItem.HidesBackButton = false;

to hide the back button, and also you can use

NavigationItem SetHidesBackButton (false, true);

if you want to hide it with animation. But I want to tell you about

NavigationItem.backBarButtonItem is null .

Well, the back button element that you see in the navigation bar belongs to the previous view controller, so you get a null value.

And if you create a button element with some strange names and additional functions (I don’t know what else you can do with it.) And add it to your NavigationItem.backBarButtonItem file, it will be shown in the next view controller that is pushed on it.

This is the reason for your part of NavigationItem.backBarButtonItem is null your question.

+9
source

to hide the back button, use the following command:

 self.navigationItem.hidesBackButton = NO; 

and then to show it again use:

 self.navigationItem.hidesBackButton = YES; 

You can set it hidden or shown anywhere in your code; it should not be in viewDidLoad

To rename what the back button shows:

  UIBarButtonItem *clearAll = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(trashMethod)]; self.navigationItem.leftBarButtonItem = clearAll; 

and just like the back button, you can set this in any method, not just viewDidLoad

let me know if you need more help

+4
source

Apple recommends setting the back button on the view controller from which you are creating a new view, and not in the viewDidLoad method.

Here's how to do it:

 SecondViewController secondView = new SecondViewController ("secondview"); UIBarButtonItem backButton = new UIBarButtonItem ("Title", UIBarButtonItemStyle.Plain); // style, target and action will be overridden, regardless of value NavigationItem.BackBarButtonItem = backButton; NavigationController.PushViewController (secondView, true); 

Please note that when creating the backBarButtonItem only the title can be set, the rest of the values ​​will be overridden.

To explicitly disable the back button:
this.navigationItem.BackBarButtonItem = nil

+4
source

Source: https://habr.com/ru/post/1346393/


All Articles