Bingo
Bingo

Reputation: 375

Bar Button Items disappear from Navigation Controller

I have a strange problem with my app I am developing. The Bar Button Items all disappear at random times.

I have a Navigation Controller with one button (as image) that takes the user to the Menu Table View Controller via push segue.

The Menu Table View Controller has 3 rows, i.e. menu options.

Each menu option takes the user to another View Controller via a push segue. Each view controller has a Back button shown using the default buttons.

It's all a pretty simple straightforward setup without any code.

I have noticed many occasions all the bar button items disappear. No back buttons, no menu button etc. Although I can still tap on the area and the buttons still work - just not visible.

I am not doing anything via code that is hiding the buttons.

I have noticed a number of times if I leave my app in the foreground and the phone goes to sleep, then when I come back the buttons are gone. Not always though.

However this is not the only time the buttons disappear. I have actually seen them disappear whilst using the menu system. But once again there's no code that I can see that is causing this.

I'm currently on iOS9, but it did the same with iOS8.

Any idea what could be the problem?

Upvotes: 2

Views: 5050

Answers (3)

Bingo
Bingo

Reputation: 375

Opps ... turns out I was to blame for the disappearing bar button items.

I was loading a SKStoreProductViewController (presents the App Store view controller) and I wanted to make the colors match my app so after a search on the web I found a solution:

UINavigationBar.appearance().tintColor = myColor

And it worked.

But this did not affect my apps Bar Button Items. It wasn't until I called MFMailComposeViewController (to compose an email) that the problem occurred.

When closing MFMailComposeViewController my apps Bar Button Items disappeared.

Well they didn't disappear, they turned the same color as the Navigation Bar, they were still there, just couldn't see them.

The solution was to set the tint color of the SKStoreProductViewController like this:

    myStoreProductViewController.view.tintColor = myColor

Upvotes: 2

Arpit Dhamane
Arpit Dhamane

Reputation: 513

These are the following things you can check, If you have inserted navigation ban in the storyboard then, check if the user interaction is enabled or not and that the navigation bar is hidden or not.

enter image description here

The second thing you can check is that if your navigation bar has some view on the bar buttons, as you are saying the methods are called when the button space is tapped. Use the debug view hierarchy while the app is built.

enter image description here

Upvotes: 1

Akash Raghani
Akash Raghani

Reputation: 557

I hope this will help you.try this code in your view didload method.

// 1
var rightAddBarButtonItem:UIBarButtonItem = UIBarButtonItem(title: "Add", style: UIBarButtonItemStyle.Plain, target: self, action: "addTapped:")
// 2
var rightSearchBarButtonItem:UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Search, target: self, action: "searchTapped:")
// 3
self.navigationItem.setRightBarButtonItems([rightAddBarButtonItem,rightSearchBarButtonItem], animated: true)

Upvotes: 0

Related Questions