可以通过编程方式创建一个 UIPopoverController,然后设置它的 viewController、passthrough 视图等:
- (IBAction)showCustomPopoverButtonHandler:(id)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];
}
但是,我想利用故事板/序列。采用这种方法时,我看不到如何获取对 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];
}
}