I've pushed my View on to the NavigationController stack, I'm in the ViewLoaded, and I find that NavigationItem.BackBarButtonItem is null. Why is that? How can I either disable it (temporarily, and I'd prefer not to hide it in this very particular case) and how could I consider renaming what it shows?
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 the part about
NavigationItem.backBarButtonItem is null
.
Well the back button item that you see on the navigation bar belongs to previous view controller so thats why you are getting null.
And if you create a bar button item with some weird name and extra features(I dont know what else you can do with it.) and add it to your NavigationItem.backBarButtonItem it will be shown in the next view controller which is gonna be pushed on top of it.
That is the reason for your NavigationItem.backBarButtonItem is null
part of your question.
Apple recommends you set the Back button from the view controller you instantiate the new view from, and not in the viewDidLoad
method.
This is 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);
Note that when creating a backBarButtonItem
, only the title can be set, the other values will be overridden.
To explicitly disable the Back button:this.navigationItem.BackBarButtonItem = nil
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With