【发布时间】:2012-04-04 20:58:20
【问题描述】:
我正在使用 iOS 5.0 SDK 和 XCode 4.2 开发一个 iOS 4 应用程序。
我必须在 UITableView 中显示一些博文。当我检索到所有 Web 服务数据后,我使用此方法创建一个 UITableViewCell:
- (BlogTableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* cellIdentifier = @"BlogCell";
BlogTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"BlogTableViewCell" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[BlogTableViewCell class]])
{
cell = (BlogTableViewCell *)currentObject;
break;
}
}
}
BlogEntry* entry = [blogEntries objectAtIndex:indexPath.row];
cell.title.text = entry.title;
cell.text.text = entry.text;
cell.photo.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:entry.photo]]];
return cell;
}
但是这一行:
cell.photo.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:entry.photo]]];
太慢了(entry.photo 有一个 http url)。
有没有办法异步加载该图像?我认为这很困难,因为 tableView:cellForRowAtIndexPath 经常被调用。
【问题讨论】:
标签: ios cocoa-touch uitableview asynchronous uiimageview