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;
Simple and effective –
Edit:
How can you add this when you are pushing this ? Add it in the
viewWillAppearorviewDidLoadof 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
NSUserDefaultsand 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.