可以通过编程方式创建一个 UIPopoverController,然后设置它的 viewController、passthrough View 等:
- (IBAction)showCustomPopoverButtonHandlerid)sender {
if (self.colorPicker == nil) {
self.colorPicker = [[ColorPickerTableViewController alloc] initWithStyle:UITableViewStylePlain];
_colorPicker.delegate = self;
self.colorPickerPopover = [[UIPopoverController alloc] initWithContentViewController:_colorPicker];
}
[self.colorPickerPopover setPassthroughViews[self.containerView]];
[self.colorPickerPopover presentPopoverFromRect:self.showCustomPopoverButton.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionRight
animated:YES];
}
但是,我想利用 Storyboard/序列。采用这种方法时,我看不到如何获取对 UIPopoverController 实例的编程引用:
有人知道怎么做吗?我希望像
UIPopoverController* pvc = self.popoverController;
我还列举了 childViewControllers 来检查它们的类类型:
// Get references to child view controllers.
for(NSUInteger index = 0; index < self.childViewControllers.count; index++){
id obj = self.childViewControllers[index];
if([obj isKindOfClass:[UIPopoverController class]]){
self.menuPopoverController = self.childViewControllers[index];
}
}
Best Answer-推荐答案 strong>
在苹果文档中找到答案:UIStoryboardPopoverSegue Class Ref
我在 prepareForSegue 中转换了 segue,并将 strong iVar 设置为 popoverController 属性,如下所示:
-(void)prepareForSegueUIStoryboardSegue *)segue senderid)sender{
if([segue.identifier isEqualToString:YOUR_SEGUE_IDENTIFIER]){
// Typical delegate setup.....
UIStoryboardPopoverSegue* ps = (UIStoryboardPopoverSegue*)segue;
self.popoverController = ps.popoverController;
[self.popoverController setPassthroughViews:/* array of views */];
}
}
像魅力一样工作。
您也可以像这样使用它(以相同的方法)
-(void)prepareForSegueUIStoryboardSegue *)segue senderid)sender{
if([segue isKindOfClass:[UIStoryboardPopoverSegue class]]){
self.menuPopoverController = ((UIStoryboardPopoverSegue*)segue).popoverController;
}
}
关于iphone - 使用 segues 获取对 UIPopoverController 的引用,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/15208114/
|