Invisible back button when view controller pushed

2019-06-17 18:33发布

I'm using a navigation controller to drill into a detail view when a cell is tapped. When I push my view controller onto the navigation controllers stack, I expect to see a back button that I can tap to pop the previous view off the stack.

The issue is that the back button isn't visible, but when tapping where it should be returns me to the previous view. What's the problem?

3条回答
闹够了就滚
2楼-- · 2019-06-17 18:56

Lets see if this helps you.

I had the same issue where I used a navigation based application and set up my search, rotation etc.. BUT, when I clicked on the table cell I was directed to the next view but that view did not have a back button present.

I tried to add a title to the back button but that did not work so this is what I did.

I opened the mainWindow.xib file and added a Bar Button Item to the group of other items inisde the window (where the file's owner is located). I then assigned an image to the button (you can add text here if you want). Then I clicked on the Navigation Item and hit command 2 to open up the Navigation item connections and chose the back bar button item and dragged it to the bar button item I wanted to use for my back button. And there you have it.

查看更多
贪生不怕死
3楼-- · 2019-06-17 19:01

Ensure you have set a title for the master view - for example in viewDidLoad add this -

self.title = @"The Title";

Weirdly, if there is no title for the parent view controller on the stack, rather than show an empty back button, the iPhone will not display a button but will allow taps on the area where it should be.

This bugged me for a long time!

查看更多
你好瞎i
4楼-- · 2019-06-17 19:06

At least as of iPhone 3.0, you can also avoid the dreaded invisible back button by setting a title on the root controller's navigation item in your main window's nib (MainWindow.xib in wizard-generated projects).

查看更多
登录 后发表回答