Reputation: 2455
My problem is that my RightBarButtonItem, in my navigationItem, disappears after the view appears a second time. The first time the view loads, it displays properly, but the second time it disappears completely.
The button is init'd in viewWillAppear as such:
UIBarButtonItem *optionsButton = [[UIBarButtonItem alloc] initWithCustomView:roundedButton];
self.navigationItem.rightBarButtonItem = optionsButton;
and i remembered to call super
I only touch my navigation controller once more:
Any ideas how this might be happening?
Upvotes: 2
Views: 1196
Reputation: 1036
Try this in viewWillAppear:
UIBarButtonItem *optionsButton = [[UIBarButtonItem alloc] initWithCustomView:roundedButton];
self.navigationItem.rightBarButtonItem = optionsButton;
self.navigationItem.rightBarButtonItem = nil;
self.navigationItem.rightBarButtonItem = optionsButton;
Upvotes: 0
Reputation: 376
I had the same problem.
If you check the subviews of your navigation-bar, you will see that the barButtons are removed and you have to create new ones.
I tried to store the arrays with buttons before, and add them in viewWillAppear but it did not work so I stayed with create new ones in viewWillAppear.
Upvotes: 1
Reputation: 2592
Implement your BarButton in ViewWillAppear method,so every time when your View Will appear ,you will find the bar button. This will resolve your problem.
- (void)viewWillAppear:(BOOL)animated
{
}
Upvotes: 1
Reputation: 28720
you can use a category to add custom image on navigation bar. Override drawRect method by creating a category on navigation bar. Search on google you will find it. If not let me know. I'll do it for you.
Upvotes: 1
Reputation: 1900
I have always added bar button items in viewDidLoad and never had any problem like yours. Try moving the bar button addition to viewDidLoad.
Upvotes: 0