我正在尝试将图片从一个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];
}
答案 0 :(得分:1)
尝试这样,
PostGameViewController *v1=[[PostGameViewController alloc]initWithNibName:@ "PostGameViewController" bundle:nil];
v1.theImg.image =[UIImage imageNamed:@"imagename.png"];
[self.navigationController pushViewController:v1 animated:YES];
答案 1 :(得分:1)
这里我在另一个视图中传递String变量,就像你可以用于图像一样。
MainView Controller中的:
UserDetailsViewController *userDetailsViewController = [[UserDetailsViewController alloc] initWithNibName:@"UserDetailsViewController" bundle:nil];
userDetailsViewController.ID = idUser;
[self.navigationController pushViewController:userDetailsViewController animated:YES];
UserDetailsViewController
中的<。>文件中的
@property(nonatomic) NSString *ID;
<。>在.m文件中(如何使用ID)
NSLog(@"ID---->%@",self.ID);
for image
UserDetailsViewController *userDetailsViewController = [[UserDetailsViewController alloc] initWithNibName:@"UserDetailsViewController" bundle:nil];
userDetailsViewController.img = [UIImage imageNamed:@"abc.png"];
[self.navigationController pushViewController:userDetailsViewController animated:YES];
<。>文件中的
@property(nonatomic) UIImage *img;
答案 2 :(得分:0)
应该是
PostGameViewController *v1=[[PostGameViewController alloc]initWithNibName:@ "PostGameViewController" bundle:nil];
v1.theImg.image = imgPicture;
[self.navigationController pushViewController:v1 animated:YES];