I am using the splitViewController template provided by Apple. On a specific action, I want to show the rootViewController
. Unfortunately, I cannot find a method that will show the popover (prog开发者_运维知识库rammatically) just as it does when you tap the bar button item.
Any Ideas? Thanks!
you can show the popover from a barButtonItem
or with your own rect with these two methods:
[self.popoverController presentPopoverFromRect:(CGRect) inView:(UIView *) permittedArrowDirections:(UIPopoverArrowDirection) animated:(BOOL)];
[self.popoverController presentPopoverFromBarButtonItem:(UIBarButtonItem *) permittedArrowDirections:(UIPopoverArrowDirection) animated:(BOOL)]
self.popoverController
is my case an ivar which stores the popover. I'm setting this variable each time in:
- splitViewController:willHideViewController:withBarButtonItem:forPopoverController:
and set it back to nil
in it's counterpart method:
- splitViewController:willShowViewController:invalidatingBarButtonItem:
heres my code:
- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {
barButtonItem.title = @"42";
self.navigationController.navigationBar.topItem.leftBarButtonItem = barButtonItem;
self.popoverController = pc;
}
- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
self.navigationController.navigationBar.topItem.leftBarButtonItem = nil;
self.popoverController = nil;
}
精彩评论