UINavigationController Back Button not visible, bu

2019-03-20 16:00发布

问题:

I have a scenario where my UINavigationController is missing the back button (left button) but tapping the left button still seems to work.

I found a similar problem posted here: UINavigationController's back button disappears? which was resolved by not setting the title to @"", but that's not my problem. Are there any other scenarios that would cause this behaviour?

UPDATE:

In case it matters here is my view hierarchy: My MainWindow contains a UINavigationView which first loads a UIViewController (this view contains a Map). When tapping on an annotation accessory button it then loads a UITableViewController. It's this view that should have the back button.

Thanks.

回答1:

Oh Man! Ok, I found the answer here: http://www.iphonedevsdk.com/forum/iphone-sdk-development/35633-back-button-missing-navigation-bar.html

It turns out that my first view (the one with the map on it) didn't have a title set (in fact I hide the navigation bar because I didn't want to show it). Even if the title WAS set on a later view the SDK doesn't seem to care. I still don't understand 100% why I could tap in the area to get it to work.

So even though I hide the first navigation bar I still need to set the title of it.

That did it!

Thanks to everyone who tried to help.



回答2:

Are you overriding the back button item -- not the same as the left button -- anywhere in your code? i.e.:

self.navigationItem.backBarButtonItem = ...

Are you setting the hidesBackButton property anywhere? i.e.:

self.navigationItem.hidesBackButton = YES;


回答3:

Other than the suggestions provided above. changing the Appearance of Navigation bar can also make Back button invisible.

UINavigationBar.appearance().tintColor = UIColor.white

Verify if you are not setting this tint color to something which blend with the background.