I have a slightly unique situation concerning popovers. I just finished adding a third navigation item (UIBarButtonItem), which I had to create programmatically, since the storyboard will only allow for two navigation items. This new button currently segues to a view controller using an identifier I set in the storyboard. Everything works as is, but I need to segue a popover instead of a push. Since this button was created in code, I can't set the anchor for the popover in the storyboard. Is there a way to set the segue type to popover in the storyboard and set its anchor programmatically using the identifier? Or will the popover have to be done completely in code? Below is what I have for the new button and current segue.
Button Initializedself.categoryButtonItem = [[UIBarButtonItem alloc]initWithTitle:NSLocalizedString(@"Cat", @"categories button") style:UIBarButtonItemStyleDone target:self action:@selector(categoryButtonDidPress:)];
self.navigationItem.rightBarButtonItems = [self.navigationItem.rightBarButtonItems arrayByAddingObject:self.categoryButtonItem];
Current Segue set to Push in storyboard.
-(void) categoryButtonDidPress:(UIBarButtonItem *)sender {
[self performSegueWithIdentifier:@"categorySegue" sender:nil];
}
The code below shows how you might include a popover in your app based on the limits provided above. This feature is not compatible with the iPhone. It may be compatible with the iPhone 6 Plus (given it's capabilities for split views). In xcode6 the view controller identifier has been removed and replaced with Storyboard ID (and possibly in later versions). This is important when instantiating the view controller with an identifier, and be sure to create a property for the UIPopOverController. Remember, this is just a starting point for any new developers.
property@property (nonatomic, strong) UIPopOverController *buttonPopOverController;
method
-(void) categoryButtonDidPress:(UIBarButtonItem *)sender {
UIStoryboard *storyboard = self.storyboard;
CategoryViewController *categoryVC = [storyboard instantiateViewControllerWithIdentifier:@"CategoryViewController "];
self.buttonPopOverController = [[UIPopoverController alloc] initWithContentViewController:categoryVC];
[self.buttonPopOverController presentPopoverFromBarButtonItem:self.categoryButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}