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



在我的主视图控制器中,我有一个按钮,提示用户从他们的照片库中选择一张照片,然后显示它(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"];}

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

在SecondViewController 中获取这个in.h文件

UIImage *imgSelected;

在seconview控制器中执行以下功能

-(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];

我手写这封信时,请检查拼写错误。希望得到帮助。

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

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

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.

最新更新