Iphone Obtain reference to UIPopoverController w/segues

Iphone Obtain reference to UIPopoverController w/segues,iphone,ios,objective-c,ipad,Iphone,Ios,Objective C,Ipad,One can programmatically create a UIPopoverController then set its viewController, passthough views etc: - (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 setPassthroughV

One can programmatically create a UIPopoverController then set its viewController, passthough views etc:

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

However, I'd like to leverage storyboards/seques. When take this approach, I don't see how to obtain a programmatic reference to the UIPopoverController instance:

enter image description here

Anybody know how to do this? I would expect something like

UIPopoverController* pvc = self.popoverController;

I've also enumerated the childViewControllers to check against their class type:

   // 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

Found answer in apple doc: UIStoryboardPopoverSegue Class Ref

I casted the segue in prepareForSegue, and set strong iVar to the popoverController property like such:

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

Works like a charm.

Alternatively you can use it like this (in the same method)

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue isKindOfClass:[UIStoryboardPopoverSegue class]]){
        self.menuPopoverController = ((UIStoryboardPopoverSegue*)segue).popoverController;
    }
}

#2

Found answer in apple doc: UIStoryboardPopoverSegue Class Ref

I casted the segue in prepareForSegue, and set strong iVar to the popoverController property like such:

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

Works like a charm.

Alternatively you can use it like this (in the same method)

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue isKindOfClass:[UIStoryboardPopoverSegue class]]){
        self.menuPopoverController = ((UIStoryboardPopoverSegue*)segue).popoverController;
    }
}

#3

Sorry, I was late to read your question, but am glad you found the answer. One advantage of implementing popovers in a segue and storyboard is that you don't have to write code to dismiss it. The popover is dismissed automatically. Also, the anchored view is set with a simple ctrl-drag.

#4

The Anchor view cannot always be set like that. For example, I have two container views and want to set the anchor to be a control within one of the container views. However most cases can be set like that.

#5

You can also set the size of the popover in prepareForSegue using something like [self.popverController setSetContentSizeForViewInPopover:CGSizeMake(600, 600)];. You also don't need a strong reference, since the segue handles retaining the view for you.

#6

Sorry, I was late to read your question, but am glad you found the answer. One advantage of implementing popovers in a segue and storyboard is that you don't have to write code to dismiss it. The popover is dismissed automatically. Also, the anchored view is set with a simple ctrl-drag.

#7

The Anchor view cannot always be set like that. For example, I have two container views and want to set the anchor to be a control within one of the container views. However most cases can be set like that.

#8

You can also set the size of the popover in prepareForSegue using something like [self.popverController setSetContentSizeForViewInPopover:CGSizeMake(600, 600)];. You also don't need a strong reference, since the segue handles retaining the view for you.