Storyboard: Dismissing Popover using delegate/protocol method

后端 未结 1 1133
庸人自扰
庸人自扰 2021-02-05 20:53

I\'ve read tons of stuff on this and while most seems to be in regards to the non-storyboard approach, I thought I had pieced bits together and figured it out. However,

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-05 21:51

    When linking to a popover controller from a storyboard segue, the popoverController property of the segue refers to a standard UIPopoverController. This controller itself has a property, contentViewController, which will represent the view controller that is actually being presented within the popover, in your case the PopViewController.

    So, your current code is setting itself as the delegate of the popover controller, when it really needs to be setting itself as the delegate of the popover's content view controller.

    You still need to keep a reference to the popover controller around, to dismiss, so keep your existing code, but make the following change:

    -(void)prepareForSegue:(UIStoryboardPopoverSegue *)segue sender:(id)sender
    {
        if ([[segue identifier] isEqualToString:@"popoverSegue"])
        {
            popover = [(UIStoryboardPopoverSegue *)segue popoverController];
            // Get a reference to the content view controller of the popover
            PopViewController *popVC = (PopViewController*)popover.contentViewController;
            // Set ourselves as the content VC's delegate
            popVC.delegate = self;
        }
    }
    

    0 讨论(0)
提交回复
热议问题