Iphone imagelibrary怀疑

时间:2012-03-23 06:12:32

标签: iphone

我有视图控制器,其中包含一个显示图像库的按钮,如果用户点击图像,选择图像将与按钮显示在同一视图中,但我想在另一个类中显示此图像?(查看控制器)。我的代码是

-(IBAction) getPhoto:(id) sender {
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;

    if((UIButton *) sender == choosePhotoBtn) {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    }   
    [self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}

它在同一视图中显示图像,但我需要在另一个视图中显示它。如何点头。

1 个答案:

答案 0 :(得分:0)

将Image存储在UIImage对象中并将其传递给您想要的viewController

在当前视图控制器中

.h声明一个UIImage对象

UIImage *selectedImage;

在.m文件中

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
   selectedImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    imageView.image = selectedImage;
}

将它传递给你想要的viewController

YourViewController *viewObj = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:[NSBundle mainBundle]];
viewObj.imageToBePassed = selectedImage;
//You should synthesize this object imageToBePassed
[self viewObj animated:YES];
[viewObj release];