2

背景:在 iPad 上,我有一个按钮,点击时会显示UIActionSheet. 此操作表有 2 个选项,相机和图库。点击相机时,拉起相机,一切正常。点击图库时,假设会显示一个包含用户照片的弹出框。

问题:在 iPad 上,UIActionSheet就像弹出窗口一样。呈现时,无法看到另一个弹出窗口。错误:Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.

我的代码:
设置操作表

- (void)imageButtonTapped:(UIButton *)sender
{
    if (_commentObject.image){
        _actionSheet = [[UIActionSheet alloc] initWithTitle:@"Action" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Remove" otherButtonTitles:nil];
        _actionSheet.tag = ACTION_IMAGE_REVIEW_TAG;
    }else{
        _actionSheet = [[UIActionSheet alloc] initWithTitle:@"Image Source" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Gallery", nil];
        _actionSheet.tag = ACTION_IMAGE_SOURCE_TAG;
    }

    if (_isPad) {
        [_actionSheet showFromRect:_imageButton.frame inView:_scrollViewContent animated:YES];
    }else{
        [_actionSheet showInView:self.view];
    }
}

代表

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    switch (actionSheet.tag) {
        case ACTION_IMAGE_SOURCE_TAG:
            switch (buttonIndex) {
                case 0:
                    [self pickImage:YES];
                    break;
                case 1:
                    [self pickImage:NO];
                    break;
                default:
                    break;
            }
                break; 
}

执行

- (void)pickImage:(BOOL)fromCamera
{
    if (fromCamera) {
        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
            UIImagePickerController* cameraPickerController = [[UIImagePickerController alloc] init];
            cameraPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
            cameraPickerController.delegate = self;
            [self presentViewController:cameraPickerController animated:YES completion:nil];
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Camera Unavailable" message:@"Your Device does not support Cameras" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
        }
    }else{
        UIImagePickerController *galleryPickerController = [[UIImagePickerController alloc] init];
        galleryPickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        galleryPickerController.delegate = self;

        if (_isPad) {
            if ([_actionSheet isVisible]) {
                [_actionSheet removeFromSuperview];
                UIPopoverController *imagePickerPopover = [[UIPopoverController alloc] initWithContentViewController:galleryPickerController];
                [imagePickerPopover presentPopoverFromRect:_imageButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
            }
        }else{
            [self presentViewController:galleryPickerController animated:YES completion:nil];
        }
    }
}

问题:我尝试从视图中删除操作表,并尝试在执行之前将其关闭pickImage。这些都不起作用。我如何展示画廊?

4

3 回答 3

2

你的问题:Error:Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.

UIPopoverController在您的 .h 文件类中创建对象。确保你的@propertyUIPopoverController是强而不是弱。

检查这个

UIPopoverController:在popover仍然可见时达到了dealloc

在弹出窗口仍然可见时达到 UIPopovercontroller 解除分配

于 2013-08-12T14:14:51.087 回答
0

仅供参考,这是一条评论,OP 要求将其作为答案。因为这解决了问题。

发生这种情况是因为您没有引用您的UIPopoverController. 为您提供强有力的参考imagePickerPopover,然后尝试。不会出现问题。

于 2013-08-13T05:26:42.160 回答
0

你可以试试这个:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        if ([actionSheet isVisible]) {
            [actionSheet dismissWithClickedButtonIndex:0 animated:NO];
        }
    }
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        UIImagePickerController *galleryPickerController = ......
    }
}
于 2014-12-29T13:57:27.350 回答