2011-06-29 48 views
0

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

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

我的问题是我怎样才能在第二个视图控制器中显示这个选定的图像?我知道如何去一个不同的观点,我只是不确定如何将图像发送到该视图。

回答

0

在SecondViewController

UIImage *imgSelected; 

在seconviewcontroller

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

现在,在第一个视图控制器做这样借此在.h文件中进行以下功能:

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

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

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

+0

感谢您的所有答案。这样做,工作很好。 –

0

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

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

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. 
相关问题