尝试异步加载图像我收到此错误“由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[valueForUndefinedKey:]:此类不符合键img的键值编码。” 我的代码是以下
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];
});
});
}
请告知我在这里哪里出错了。谢谢马尤尔