获取对带有segues的UIPopoverController的引用

时间:2013-03-04 18:10:11

标签: iphone ios objective-c ipad

可以通过编程方式创建UIPopoverController然后设置其viewController,passthough视图等:

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

但是,我想利用故事板/ seques。采用这种方法时,我不知道如何获得对UIPopoverController实例的编程引用:

enter image description here

有人知道怎么做吗?我期待像

这样的东西
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];
        }
    }

1 个答案:

答案 0 :(得分:4)

在apple doc中找到答案:UIStoryboardPopoverSegue Class Ref

我在prepareForSegue中输入了segue,并将强大的iVar设置为popoverController属性,如:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)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)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue isKindOfClass:[UIStoryboardPopoverSegue class]]){
        self.menuPopoverController = ((UIStoryboardPopoverSegue*)segue).popoverController;
    }
}