如果图像未从 url 加载,我如何将本地 image.png 添加到单元格?
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
DetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSURL* url = [NSURL URLWithString:[arrayOfImages objectAtIndex:indexPath.row]];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse * response,
NSData * imagedata,
NSError * error) {
if (!error){
UIImage* image = [[UIImage alloc] initWithData:imagedata];
cell.flowerImage.image = image;
}
}];
return cell;
}
arrayOfImages
- 我从 json 解析的 url 字符串数组。