0

This is basically in continuation of: Dismissing iPad UIPopoverController when BarButtonItem is pushed while it's open, however I see the issue as large enough that it warranted another question.

Basically, they wanted to show the popover when the barbuttonitem (provided by the splitviewcontroller) is clicked, and then hide the popover when the same barbuttonitem is clicked again. They solved it by calling:

- (void)splitViewController:(UISplitViewController*)svc popoverController:(UIPopoverController*)pc willPresentViewController:(UIViewController *)aViewController{
    if ([popoverController isPopoverVisible]) {
        [popoverController dismissPopoverAnimated:YES];
    }
}

However, I've come to the problem where on the first click of the barbuttonitem, this method is called correctly and it displays the popover. However, on any subsequent clicks of the barbuttonitem while the popover is open, this method is not called.

More puzzling, when I close the popover view through other means (clicking outside of the popover), then the popover closes automatically. However, a click on the button itself does not close the popover, nor does it call that "willPresentViewController" method.

Are there other means of catching this button click action? Or any thoughts on why the method is not called on a click of the button while the popover is open?

4

1 回答 1

0

因此,当您再次单击“主”按钮时,似乎正常的 UISplitViewController 会自动关闭,但是,我使用的是 MGSplitViewController。所以我修改了 MGSplitViewController.m (特别是 showMasterPopover :) 来处理当它第二次单击按钮时自行解散,如下所示:

-(IBAction)showMasterPopover:(id)sender
{
    if (_hiddenPopoverController && !(_hiddenPopoverController.popoverVisible)) 
    {
        // Inform delegate.
        if (_delegate && [_delegate respondsToSelector:@selector(splitViewController:popoverController:willPresentViewController:)]) 
        {
            [(NSObject <MGSplitViewControllerDelegate> *)_delegate splitViewController:self popoverController:_hiddenPopoverController willPresentViewController:self.masterViewController];
        }
        // Show popover.
        [_hiddenPopoverController presentPopoverFromBarButtonItem:_barButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
    else if(_hiddenPopoverController && _hiddenPopoverController.popoverVisible)
    {
        [_hiddenPopoverController dismissPopoverAnimated:YES];
    }
}
于 2012-05-30T15:51:30.730 回答