【问题标题】:dismissViewControllerAnimated mysteriously working for iPhoneDismissViewControllerAnimated 神秘地为 iPhone 工作
【发布时间】:2013-07-11 21:02:51
【问题描述】:

所以我有一个 iPhone 应用程序可以选择和图像,然后出现一个弹出窗口。您可以选择取消弹出框,这会关闭弹出框,这是以下方法的作用。当我测试我的应用程序时,我可以从照片库中选择一张图片,让图片选择器被关闭,但随后 imagePicker 又回来了。但是,当我测试我的应用程序时,没有打印以下方法的注释,并且我没有在其他地方实现 dimiss 调用,所以这怎么可能发生???

- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
    if ([popoverController isPopoverVisible]) {
        NSLog(@"imagePickerControllerDidCancel called for iPad");
        [popoverController dismissPopoverAnimated:YES];
    }
}
else {
    NSLog(@"imagePickerControllerDidCancel called for iPhone");
    [self dismissViewControllerAnimated:YES completion:nil];
}

[picker release];
[self pickImage];
}

用于呈现视图控制器的代码:

switch (buttonIndex) {
    case 0: { //photo library
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
            UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
            imagePicker.delegate = self;
            imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
                if ([popoverController isPopoverVisible]) {
                    [popoverController dismissPopoverAnimated:YES];
                }
                else {
                    popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
                    popoverController.delegate = self;
                    [popoverController presentPopoverFromRect:CGRectMake( 250, -50, 320, 480 )
                                                       inView:[self view]
                                     permittedArrowDirections:UIPopoverArrowDirectionUp
                                                     animated:YES];
                }
            }
            else {
                [self presentViewController:imagePicker animated:TRUE completion:nil];
            }
        } else {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Photo library is empty or unavailable" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];
        }
        break;
    }

【问题讨论】:

  • 您是否在图像选择器控制器上设置了代理?
  • 是的,我在上面添加了该代码。
  • 您是否尝试过使用断点来确定您的“imagePickerControllerDidCancel”方法是否被调用?
  • [self pickImage] 方法有什么作用?也许您要展示控制器 2 次?
  • @QuinnLiu 试试我的答案,让我知道伙计.. :)

标签: iphone ios6 uiviewcontroller dismiss


【解决方案1】:

请在 iphone 上尝试此代码,然后检查

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;
    imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

    [self presentModalViewController:imagePicker animated:TRUE];
}

【讨论】:

    【解决方案2】:

    试试这个

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
    {
        [popoverController dismissPopoverAnimated:true];
        [picker dismissModalViewControllerAnimated:YES];
    
    }
    

    或在imagePickerControllerDidCancel: 方法中,如下所示...

    - (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    
            [popoverController dismissPopoverAnimated:true];
            [picker dismissModalViewControllerAnimated:YES];        
    }
    

    【讨论】:

    • @QuinnLiu 试试我上面的答案,如果有问题请告诉我.. :)
    【解决方案3】:

    [自选图片];

    -(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
        if ([popoverController isPopoverVisible]) {
            NSLog(@"imagePickerControllerDidCancel called for iPad");
            [popoverController dismissPopoverAnimated:YES];
        }
    }
    else {
        NSLog(@"imagePickerControllerDidCancel called for iPhone");
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    
    [picker release];
    [self pickImage];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-15
      • 2021-02-05
      • 2020-10-24
      • 1970-01-01
      • 2014-12-08
      • 2015-05-20
      • 1970-01-01
      相关资源
      最近更新 更多