This may not be possible, but I\'m hoping someone will have an idea how to do it.
I have an app I\'m porting from iPhone only to Universal. On the iPhone, I\'m using a
I was curious about this too so I made a quick test project. You're right, there doesn't seem to be a way to configure the popover segue at runtime or add an anchor point to a button that's not in the view hierarchy using Interface Builder.
My solution was to set everything up in IB with the UIBarButtonItem
visible and connected to an IBOutlet
property, then remove it from the navigation bar in -viewDidLoad
:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = nil;
}
Then I simply add it back or remove it by tapping another button:
- (IBAction)toggleBarButtonItem:(id)sender
{
UIBarButtonItem *item = (self.navigationItem.rightBarButtonItem == nil) ? self.popoverBarButtonItem : nil;
[self.navigationItem setRightBarButtonItem:item animated:YES];
}
You could conditionally keep or remove the button in -viewDidLoad
the same way. The segue remains anchored to the UIBarButtonItem
.