代码之家  ›  专栏  ›  技术社区  ›  Fire Fist

如何在iOS中检查UIPopOverController的解除?

  •  -1
  • Fire Fist  · 技术社区  · 11 年前

    我需要设置 UIPopOverController 从库中选择照片。

    所以我写了以下代码。

    self.imagePickerController = [[UIImagePickerController alloc] init];
        self.imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
        self.imagePickerController.sourceType = sourceType;
        [self.imagePickerController setDelegate:self];
    
        UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:self.imagePickerController];
    
        [popover presentPopoverFromRect:self.btnArchive.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
        imagePickerPopover = popover;
    

    它出现了,我从照片库中选择了一张照片,在我从库中选择后,我用以下代码驳回了PopOver。

    [self.imagePickerPopover dismissPopoverAnimated:NO];
    

    我需要显示从照片库中选择的图像,所以我在- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 方法

    UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
    
    [self dismissViewControllerAnimated:YES completion:^ {
    
    // Codes Here after dismiss PopOverView and chosen photo from library
    
    }];
    

    但它不起作用。我该如何检查 UIPopOver控制器 ?

    2 回复  |  直到 11 年前
        1
  •  2
  •   Hooda    11 年前
    - (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController   
    - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
    

    这是popover控制器解除时的委托方法

        2
  •  1
  •   Noor Ryan    11 年前

    将popover的委托设置为self,也可以使用两个popover委托,即

    /* Called on the delegate when the popover controller will dismiss the popover. Return NO to prevent the dismissal of the view.
     */
    - (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController;
    /* Called on the delegate when the user has taken action to dismiss the popover. This is not called when -dismissPopoverAnimated: is called directly.
     */
    - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController;
    

    然后将MainViewController实例设置为popover的委托

    popover.delegate = self;