0
我正在从JSON对象读取数据并将image属性传递给其他viewcontroller。在我做之前,我想用硬编码的UiImage测试下面的代码,它工作得很好。用segue传递UIImage
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
GrillMenuSingleFoodViewController *gVC = [segue destinationViewController];
if ([segue.identifier isEqualToString:@"isMoreDetail"]) {
[gVC setImage:[UIImage imageNamed:@"Ali_nazik.jpg"]];
}
}
但是下面的代码不起作用。即使我得到imagedata,一旦我传递给其他viewcontroller它显示为零。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
GrillMenuSingleFoodViewController *gVC = [segue destinationViewController];
if ([segue.identifier isEqualToString:@"isMoreDetail"]) {
NSString *imageURLString=[menuArray[indexPath.row]valueForKey:@"picture"];;
NSURL *url = [NSURL URLWithString:imageURLString];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
UIImage *tmpImage = [[UIImage alloc] initWithData:data];
[gVC setImage:[UIImage imageWithData:data]];
}
}
什么是您的 “'gVC'” “'setImage'” 是什么样子?它是“@属性”还是它的某种方法? –
此外,因为你去创造一个“'tmpImage'”(你不使用)的麻烦,你检查作出某些“'tmpImage'”是一个有效的对象,而不是空? –
@property(弱,非原子)的UIImage *图像; foodImageView.image =图像; – casillas