如何将图像从一个视图传递到另一个视图
我想从一个UIViewController
传递图像到另一个UIViewController
。 但我没有得到成功。 我的代码如下。
PostGameViewController *v1=[[PostGameViewController alloc]initWithNibName:@ "PostGameViewController" bundle:nil]; v1.theImg = imgPicture; [self.navigationController pushViewController:v1 animated:YES];
//在“.h”
@interface PostGameViewController : UIViewController{ UIImage *img; UIImageView *theImg; } @property(nonatomic,retain)IBOutlet UIImageView *theImg; @property(nonatomic,retain)UIImage *img; -(IBAction)clickFacebook:(id)sender;
//在“.m”
- (void)viewDidLoad { [super viewDidLoad]; [theImg setImage:img]; }
在这里,我已经在另一个视图中传递stringvariables的方式可以用于图像。
在MainView控制器中:
UserDetailsViewController *userDetailsViewController = [[UserDetailsViewController alloc] initWithNibName:@"UserDetailsViewController" bundle:nil]; userDetailsViewController.ID = idUser; [self.navigationController pushViewController:userDetailsViewController animated:YES];
在UserDetailsViewController
在.h文件中
@property(nonatomic) NSString *ID;
在.m文件(如何使用ID)
NSLog(@"ID---->%@",self.ID);
图像
UserDetailsViewController *userDetailsViewController = [[UserDetailsViewController alloc] initWithNibName:@"UserDetailsViewController" bundle:nil]; userDetailsViewController.img = [UIImage imageNamed:@"abc.png"]; [self.navigationController pushViewController:userDetailsViewController animated:YES];
在.h文件中
@property(nonatomic) UIImage *img;
像这样尝试,
PostGameViewController *v1=[[PostGameViewController alloc]initWithNibName:@ "PostGameViewController" bundle:nil]; v1.theImg.image =[UIImage imageNamed:@"imagename.png"]; [self.navigationController pushViewController:v1 animated:YES];
应该
PostGameViewController *v1=[[PostGameViewController alloc]initWithNibName:@ "PostGameViewController" bundle:nil]; v1.theImg.image = imgPicture; [self.navigationController pushViewController:v1 animated:YES];