Ios 使用segue传递图像时指针类型不兼容?目标c Xcode
当我尝试使用segue在第二个viewController上更改图像时,我遇到了一个问题,即: 将“UIimage*\u Nullable”指定给“NSArray”的指针类型不兼容 我的代码是这样的:Ios 使用segue传递图像时指针类型不兼容?目标c Xcode,ios,objective-c,uiimageview,segue,Ios,Objective C,Uiimageview,Segue,当我尝试使用segue在第二个viewController上更改图像时,我遇到了一个问题,即: 将“UIimage*\u Nullable”指定给“NSArray”的指针类型不兼容 我的代码是这样的: - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if ([[segue identifier] isEqualToString:@"the_segue"]){ SecondViewControll
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:@"the_segue"]){
SecondViewController *transferViewController = [segue destinationViewController];
transferViewController.theimageView.image=@"photo.jpg";
}
}
谁能帮我解决这个问题,谢谢 您正在将图像视图的图像属性(即UIImage)指定给字符串
我想您需要的是
transferViewController.theimageView.image=[UIImage-imagename:@“photo.jpg]”代码>您正在使用字符串来表示UIImage。在这种情况下,编译器会向您发出警告:“将不兼容的指针类型分配给“UIImage*\u Nullable”到“NSArray”
只要做:-
transferViewController.theimageView.image = [UIImage imageNamed:@"ImageName"];
或
另外,你不需要提及图像的扩展名,只要提及名称,当有两个图像的名称相似但扩展名不同时,扩展名是必需的
修复字符串与图像的问题后,您可能会遇到以下问题:
[transferViewController.theimageView setImage:[UIImage imageNamed:@"ImageName"]];