2016-03-15 152 views
0

我想在UIImagePickerController中选择一个图像后创建一个预览图像的视图。我试图创建一个视图控制器,并推动选择器控制器到另一个视图控制器。如何在UIImagePickerController中选择图像后设置预览图像的视图?

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    ImagePreviewController *ipc = [self.storyboard instantiateViewControllerWithIdentifier:@"ImagePreviewController"]; 
    UIImage * image = [info valueForKey:UIImagePickerControllerOriginalImage]; 

    ipc.selectedImage = image; 
    [picker pushViewController:ipc animated:YES]; 
} 

正如你所看到的,我试图将UIImagePickerController推送到另一个视图并尝试预览它。但不幸的是,当我调试它时,ipc对象显示为空。我明白,UIImagePickerController是从UINavigationController继承的。是否因为在此导航控制器中找不到我的ipc视图?如果是的话,我如何将它添加到UIImagePickerController中,以便它可以推送到预览图像视图?如果不是,我如何正确设置预览图像视图?

更新:如果我把

ImagePreviewController *ipc = [ImagePreviewController alloc]init]; 

相反,当它推动,这是一个黑色的屏幕。

回答

1

您应该驳回影像选择器,然后出示您的自定义UIViewController

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    UIViewController *presentingViewController = picker.presentingViewController; 
    ImagePreviewController *ipc = [self.storyboard instantiateViewControllerWithIdentifier:@"ImagePreviewController"]; 
    UIImage * image = [info valueForKey:UIImagePickerControllerOriginalImage]; 

    ipc.selectedImage = image; 

    [presentingViewController dismissViewControllerAnimated:YES completion:^(BOOL animated){ 
     [presentingViewController presentViewController:ipc animated:YES completion:nil]; 
    }]; 
} 
+0

工控机显示这是零,但我101%肯定它在那里。 –

+0

而且我也试过你的代码,但不幸的是屏幕仍然是黑色的。 –

+0

原来是我的ImagePreviewController类的一些错误。你的代码很好。谢谢您的帮助。 –

相关问题