我正在使用由苹果提供的splitViewController模板。在特定的操作中,我想显示
有什么想法吗?谢谢!
rootViewController
。不幸的是,我找不到一个方法可以像你点击工具栏按钮项时那样(以编程方式)显示弹出窗口。有什么想法吗?谢谢!
rootViewController
。不幸的是,我找不到一个方法可以像你点击工具栏按钮项时那样(以编程方式)显示弹出窗口。你可以使用这两个方法从 barButtonItem
或自己的矩形中显示弹出窗口:
[self.popoverController presentPopoverFromRect:(CGRect) inView:(UIView *) permittedArrowDirections:(UIPopoverArrowDirection) animated:(BOOL)];
[self.popoverController presentPopoverFromBarButtonItem:(UIBarButtonItem *) permittedArrowDirections:(UIPopoverArrowDirection) animated:(BOOL)]
self.popoverController
是我的情况下存储弹出窗口的实例变量。我每次在以下位置设置此变量:
- 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;
}
presentPopoverFromBarButtonItem:
方法。您必须转发该工具栏按钮(您还必须将其保存在变量中或通过查找视图元素来找到所需的按钮)。箭头方向在这种情况下将向上。[它不是自定义视图,而是它将弹出的矩形。在这里,它将是您的工具栏按钮的矩形] - user207616[self.popoverController presentPopoverFromBarButtonItem:[[self.toolbar items] objectAtIndex:0] permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
- user207616