UIImagePicker在一个视图中,将所选图像发送到第二个视图

时间:2011-06-29 13:59:27

标签: iphone

在我的主视图控制器中,我有一个按钮,提示用户从他们的照片库中选择一张照片然后显示它(img),如下所示:

-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
[picker release];}


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

我的问题是如何在第二个视图控制器中显示所选图像?我知道如何进入不同的视图,我只是不确定如何将图像发送到该视图。

3 个答案:

答案 0 :(得分:0)

如果视图控制器已经实例化,即它位于导航堆栈中当前视图控制器的下方,则可以考虑delegatesnotifications

如果尚未创建,则将图像保存在实例变量中,并在按下下一个视图控制器时将其传递。

答案 1 :(得分:0)

在SecondViewController

中的.h文件中
UIImage *imgSelected;

在seconviewcontroller中创建以下功能

-(void)setImage:(UIImage *)imgCaptured{
    imgSelected=imgCaptured;
}

现在在第一个视图中,控制器是这样的:

SecondViewControler *objSecond = [[SecondViewController] initwithNibName:@"secondview.xib" bundle:nil];

[objSecond setImage:[info objectForKey:@"UIImagePickerControllerOriginalImage"]];
[self.navigationController pushViewController:objSecond animated:YES];
[objSecond release];

我手写这个时请检查拼写错误。希望这有帮助。

答案 2 :(得分:0)

example


firstviewcontroller .h file

        before @interface 

        use @class secondViewcontroller;


declare this inside of @interface  with

        secondViewcontroller *sVC;


then in firstViewController.m file 

        before @implementation

        use 

    #import "secondViewcontroller.h"


then




-------------------

secondVC.h file

        @interface inside declare this

        say UIImage *secondimage;

        and sythasize them.








-------------------


after this 

        in firstViewcontroller.h viewdidload create this sVC by alloc and initwithnibname then

        sVC.secondimage=urfirstImage;

        now while u push this sVC controller to navigation controller u can show that in UIImageView.