Ios 如何将图像从一个视图传递到另一个视图

Ios 如何将图像从一个视图传递到另一个视图,ios,Ios,我正在尝试将图像从一个UIViewController传递到另一个UIViewController。但我没有成功。 我的代码如下 PostGameViewController *v1=[[PostGameViewController alloc]initWithNibName:@ "PostGameViewController" bundle:nil]; v1.theImg = imgPicture; [self.navigationController pushViewContro

我正在尝试将图像从一个
UIViewController
传递到另一个
UIViewController
。但我没有成功。 我的代码如下

  PostGameViewController *v1=[[PostGameViewController alloc]initWithNibName:@ "PostGameViewController" bundle:nil];
  v1.theImg = imgPicture;
  [self.navigationController pushViewController:v1 animated:YES];
//在“.h”中

//在“.m”中

试着这样,

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

在这里,我用另一种方式传递字符串变量,这种方式和您在图像中使用的方式相同

在MainView控制器中:

UserDetailsViewController *userDetailsViewController = [[UserDetailsViewController alloc] initWithNibName:@"UserDetailsViewController" bundle:nil];
    userDetailsViewController.ID = idUser;
    [self.navigationController pushViewController:userDetailsViewController animated:YES];
UserDetailsViewController

在.h文件中

@property(nonatomic) NSString *ID;
@property(nonatomic) UIImage *img;
在.m文件中(如何使用ID)


为了形象

UserDetailsViewController *userDetailsViewController = [[UserDetailsViewController alloc] initWithNibName:@"UserDetailsViewController" bundle:nil];
        userDetailsViewController.img = [UIImage imageNamed:@"abc.png"];
        [self.navigationController pushViewController:userDetailsViewController animated:YES];
在.h文件中

@property(nonatomic) NSString *ID;
@property(nonatomic) UIImage *img;

显示警告不兼容指针tpyes从uimageview分配给UIImage请发布图像图片的代码,只有这样我们才能得到清晰的想法
UIImage*imgPictute=[UIImage imagename:@“background”]此处缺少文件的扩展名。例如,UIImage*imageFromBundle=[UIImage ImageName:@“imagres.jpeg”],必须使用ExtensionDar Dhawal引用图像。我正在尝试传递图像。请检查我的代码。告诉我问题出在哪里。Ishant Tiwari尝试了@sunny answer?imgPicture有效吗?。你能把它的代码也贴出来吗
@property(nonatomic) UIImage *img;