gpt4 book ai didi

ios - 由于未捕获的异常 'NSUnknownKeyException' 而终止应用程序此类不符合 key .img 的键值编码

转载 作者:行者123 更新时间:2023-11-28 22:32:24 28 4
gpt4 key购买 nike

尝试异步加载图像时出现此错误“由于未捕获的异常‘NSUnknownKeyException’而终止应用程序,原因:‘[valueForUndefinedKey:]:此类不符合键值编码关键图片'"我的代码如下

 NSString *str = "URL of an image";

NSMutableDictionary *record = [NSMutableDictionary dictionary];
[record setObject:str forKey:@"img"];

record = [_array objectAtIndex:indexPath.row];



dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
if ([record valueForKey:@"img"]) {
NSLog(@"in if");
cell.m_img.image = [record valueForKey:@"img"];
} else {
dispatch_async(queue, ^{
NSLog(@"in else");
NSURL *imageurl = [[NSURL alloc] initWithString:str];
NSData *image = [[NSData alloc] initWithContentsOfURL:imageurl];

dispatch_async(dispatch_get_main_queue(), ^{
[record setValue:[UIImage imageWithData:image] forKey:@"img"];

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
});
});
}

请告知我哪里出错了。谢谢马约尔

最佳答案

替换

[record valueForKey:@"img"]

[record objectForKey:@"img"]

关于ios - 由于未捕获的异常 'NSUnknownKeyException' 而终止应用程序此类不符合 key .img 的键值编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17024183/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com