SplitViewController模板手动显示弹出窗口?

时间:2011-10-07 21:09:38

标签: ios ipad uisplitviewcontroller uipopovercontroller show

我正在使用Apple提供的splitViewController模板。在特定操作上,我想显示rootViewController。不幸的是,我找不到一个方法来显示popover(以编程方式),就像点击按钮项一样。

任何想法?谢谢!

1 个答案:

答案 0 :(得分:12)

您可以使用以下两种方法从barButtonItem或使用您自己的rect显示弹出窗口:

[self.popoverController presentPopoverFromRect:(CGRect) inView:(UIView *) permittedArrowDirections:(UIPopoverArrowDirection) animated:(BOOL)];
[self.popoverController presentPopoverFromBarButtonItem:(UIBarButtonItem *) permittedArrowDirections:(UIPopoverArrowDirection) animated:(BOOL)]

self.popoverController是我的情况,一个存储popover的ivar。我每次都在设置这个变量:

- splitViewController:willHideViewController:withBarButtonItem:forPopoverController:

并在其对应方法中将其设置回nil

- splitViewController:willShowViewController:invalidatingBarButtonItem:

继承我的代码:

- (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;
}