How to dismissPopoverAnimated on iPad with UIPopoverController in MKMapView (SDK3.2)

后端 未结 2 1734
清歌不尽
清歌不尽 2021-02-08 22:01

I have a MKMapView (also a UIPopoverControllerDelegate) with Annotations. This MapView has, in the MKTestMapView.h file, a UIPopoverController* popoverCo

2条回答
  •  天命终不由人
    2021-02-08 22:14

    Here is another simple solution.

    I found that we should follow the following steps for clearly dismissing popovers.

    1. dismiss a popover.
    2. release a view loaded by the popover.

    Before iOS8, almost all of us may release a view loaded by a popover first, and then we programmatically dismiss the popover. However, in iOS8, we do the steps in revers.

    Before iOS8, my code of dismissing a popover

    // creating a popover loading an image picker
    picker = [[UIImagePickerController alloc] init];
    ...
    pickerPopover = [[UIPopoverController alloc] initWithContentViewController:picker];
    [pickerPopover presentPopoverFromRect:aFrame inView:aView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    
    // dismissing the popover
    [picker.view removeFromSuperview]; // (1) release a view loaded by a popover
    [picker release], picker = nil;
    
    if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
        [pickerPopover dismissPopoverAnimated:YES]; // (2) dismiss the popover
    }
    

    In iOS8, the dismissing code part should be changed as below,

    if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
        [pickerPopover dismissPopoverAnimated:YES];  // (2) dismiss the popover first
    }
    
    [picker.view removeFromSuperview]; // (1) and then release the view loaded by the popover
    [picker release], picker = nil;
    

提交回复
热议问题