解除ViewControllerAnimated神秘地为iPhone工作

解除ViewControllerAnimated神秘地为iPhone工作,iphone,ios6,uiviewcontroller,dismiss,Iphone,Ios6,Uiviewcontroller,Dismiss,所以我有一个iPhone应用程序,可以拾取图像,然后弹出一个popover。您可以选择取消popover,它将取消popover,这是以下方法的作用。当我测试我的应用程序时,我可以从照片库中选取一幅图像,让图像选取器关闭,然后图像选取器返回。然而,当我测试我的应用程序时,以下方法的注释没有被打印出来,并且我没有在其他地方实现dimiss调用,所以这怎么可能发生 - (void) imagePickerControllerDidCancel:(UIImagePickerController *)p

所以我有一个iPhone应用程序,可以拾取图像,然后弹出一个popover。您可以选择取消popover,它将取消popover,这是以下方法的作用。当我测试我的应用程序时,我可以从照片库中选取一幅图像,让图像选取器关闭,然后图像选取器返回。然而,当我测试我的应用程序时,以下方法的注释没有被打印出来,并且我没有在其他地方实现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;
    }

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

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

    [self presentModalViewController:imagePicker animated:TRUE];
}
试试这个

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

}
或者在
ImagePickerController IDCancel:
方法中,如下面所示

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

        [popoverController dismissPopoverAnimated:true];
        [picker dismissModalViewControllerAnimated:YES];        
}
[自我形象]


您是否在映像选择器控制器上设置了委托?是的,我已在上面添加了该代码。您是否尝试使用断点来确定是否正在调用“ImagePickerController IDCancel”方法?[self-PickerImage]方法做什么?也许你给控制器演示了两次?@QuinnLiu试试我的答案,让我知道,伙计:)@QuinnLiu请尝试我的上述答案,如果有任何问题,请告诉我:)
-(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];
}