当前位置:  开发笔记 > 编程语言 > 正文

使用UIImagePickerController选择图像后,照片库视图停留在屏幕上

如何解决《使用UIImagePickerController选择图像后,照片库视图停留在屏幕上》经验,为你挑选了1个好方法。

通过照片库中的UIImagePickerController接口选择图片后,即使我在imagePickerController调用dismissModelViewControllerAnimated:didFinishPickingImage:editingInfo,照片库视图也会保持显示状态.

有没有人见过这个?这些是我正在使用的三种相关方法:

- (IBAction)choosePictureFromLibrary:(id)sender {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        UIImagePickerController* picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsImageEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentModalViewController:picker animated:YES];
        [picker release];
    }
    else {
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error accessing Photo Library" message:@"This device does not support a Photo Library." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}


- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)image editingInfo:(NSDictionary*)editingInfo {   
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Picture picked!" message:@"You picked a picture!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];

    [picker dismissModalViewControllerAnimated:YES];
}


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

我原本以为调用imagePickerController:didFinishPickingImage:editingInfo会完全关闭Photo Library视图,但似乎没有.还有什么我必须做才能让它消失吗?



1> 小智..:

您需要访问选择器的viewController而不是选择器本身.请尝试使用此行.

[[picker parentViewController] dismissModalViewControllerAnimated:YES];

推荐阅读
Chloemw
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有