Reputation: 4732
I have a a UIViewController
that is pushed to by two different views in my app.
One time it is a modal view, so I have the right navbar
button set to Done
and it dismisses the view.
At another time in my app, this same view is pushed to, but not modally, thus I don't want this button to show. I tried adding this when pushing it, but no luck.
self.navigationItem.rightBarButtonItem.enabled = NO;
Upvotes: 0
Views: 102
Reputation: 12325
Simple and effective -
self.navigationItem.rightBarButtonItem = nil;
Edit:
How can you add this when you are pushing this ? Add it in the viewWillAppear
or viewDidLoad
of the viewController you want to see this is in.
You can check for a certain condition.
For this, you will have to make the viewControllers communicate with each other. For that, you will need to use NSUserDefaults
and set an integer for a key.
You can assign two different integers logically and use them as the condition for showing/not showing the rightBarButtonItem
.
Good Luck.
Upvotes: 1
Reputation: 3659
You can check the parent view controller for whether it has the modalViewController property set
if (self.parentViewController.modalViewController == self)
{
// add button
}
Upvotes: 2