8

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.

Community
  • 1
  • 1
cagreen
  • 1,627
  • 1
  • 14
  • 29
  • Maybe the back button's `hidden` property is set to `NO`?? – Jacob Relkin Mar 21 '10 at 02:45
  • give it an actual name instead: @"My VC" to test for sure. Also it is the previous VC not the new one which you must give a title to (just in case) – Corey Floyd Mar 21 '10 at 02:51
  • Jacob - I don't think that's it. I've searched my code and I make no reference to the left button at all, never mind the hidden property. Corey - Good idea. I tried that, from both spots, and my title updates as expected, but still no luck with the button. I'll update my original questions with my view hierarchy in case that makes a difference. – cagreen Mar 21 '10 at 03:06

4 Answers4

16

Oh Man! Ok, I found the answer in an article on iphonedevsdk.com, now defunct.

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.

wjl
  • 7,143
  • 1
  • 30
  • 49
cagreen
  • 1,627
  • 1
  • 14
  • 29
  • Thanks for that - I have a segmented control instead of a title and still I had to set the view title in order to see the back button on the next view. Nevermind noone can see the title behind the segmented control. – dchakarov Oct 16 '11 at 01:31
  • The missing title is the culprit. Eg, in the viewDidLoad, just add self.title = @"Home"; and the button will appear. – Jacob Mouka Mar 08 '12 at 22:06
2

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.

soan saini
  • 230
  • 3
  • 9
0

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;
Shaggy Frog
  • 27,575
  • 16
  • 91
  • 128
  • I'm not doing either in my code. I don't see anything in IB that looks suspicious either (though I may be overlooking it). In my view the leftBarButton and backBarButton are both nil. Early on in my project I did programmatically create another leftbarbutton but have since removed it and all reference to it. Could there still be some artifact left over that I can't see? – cagreen Mar 21 '10 at 03:25
0

I had a similar (although not exactly the same) situation with a customized back button text was disappearing while the arrow could be seen UINavigationController custom back button disappears from NavigationBar

So if anyone is facing a similar situation with disappearing back button text on a customized back button, here is my scenario and fix.

I customized my back button inside a custom NavigationController class as follows:

private func customizeBackButton() {
    let backImage = UIImage(named: "BackButton")?.withRenderingMode(.alwaysOriginal)
    navigationBar.backIndicatorImage = backImage
    navigationBar.backIndicatorTransitionMaskImage = backImage
    
    UIBarButtonItem.appearance().setTitleTextAttributes([
      NSAttributedString.Key.foregroundColor: UIColor.panoStoryYellow,
      NSAttributedString.Key.font: UIFont(name: "Montserrat-SemiBold", size: 15)!
    ], for: .normal)
}

This gave me:

UINavigationController custom back button

Now when I tapped on the back button text, the text disappeared: UINavigationController UINavigationBarButton back button disappears

I made sure that I followed all the above answers such as setting titles making sure the tint color is valid etc. however this did not work.

In my case, I needed to set attributes even for the highlighted state of the back button as follows:

UIBarButtonItem.appearance().setTitleTextAttributes([
      NSAttributedString.Key.foregroundColor: UIColor.panoStoryYellow,
      NSAttributedString.Key.font: UIFont(name: "Montserrat-SemiBold", size: 15)!
], for: .highlighted)

After this, the back button text never disappeared

Shawn Frank
  • 4,381
  • 2
  • 19
  • 29