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: ポップオーバーがまだ表示されている間に dealloc に到達しました

ポップオーバーがまだ表示されている間に UIPopovercontroller の割り当て解除に達した

于 2013-08-12T14:14:51.087 に答える
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 に答える
0

参考までに、これはコメントであり、OPはそれを回答として要求しました。これで問題が解決したからです。

への参照がないために発生していますUIPopoverController。強力なリファレンスを用意してimagePickerPopoverから試してください。問題は発生しません。

于 2013-08-13T05:26:42.160 に答える