传递用UIImagePickerController捕获的图像

时间:2014-10-28 11:45:59

标签: ios objective-c xcode uiimagepickercontroller

我有这段代码:

-(void)add
{
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]==NO)
    {

        NSLog(@"No Camera");


    }
    else
    {
        cameraUI=[[UIImagePickerController alloc] init];
        cameraUI.delegate=self;
        cameraUI.allowsEditing=YES;
        cameraUI.sourceType=UIImagePickerControllerSourceTypeCamera;
        [self presentViewController:cameraUI animated:YES completion:nil];

    }

}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    self.photo=[info objectForKey:UIImagePickerControllerOriginalImage];

}

现在我需要在另一个名为SaveViewController的视图中传递照片,而不在此字段中使用segue:

@property(弱,非原子)IBOutlet UIImageView * imageField;

3 个答案:

答案 0 :(得分:0)

使用

 SaveViewController *saveView = [[SaveViewController alloc]init];

 saveView.imageField.image = self.photo;

//push saveView

答案 1 :(得分:0)

您可以创建所需视图控制器的对象(在本例中为SaveViewController)并设置属性。然后,当您需要调用该视图时,您必须使用您创建的同一对象来呈现该视图。例如,

self.photo = [info objectForKey:UIImagePickerControllerOriginalImage]; SaveViewController *svc = [[SaveViewController alloc] init]; svc.imageField.image = self.photo; [self.navigationController presentViewController:svc animated:YES completion:nil];

答案 2 :(得分:0)

您可以在标头文件中创建UIImage *passImg。在ImagePickerDelegate方法中分配

self.passImg = [info objectForKey:UIImagePickerControllerOriginalImage];

然后当你推动时:

SaveViewController *savedVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SaveViewController"];
savedVC.imageField.image = passImg;
[self.navigationController pushViewController:savedVC animated:YES];

如果popViewController使用 NSNotificationCenter