我在情节提要中的 tableviewcell 中遇到了 UIImage 问题。当我在表格视图中滚动单元格时,它每次都从服务器请求数据,因此单元格非常慢。我看过这个视频 ,但它在情节提要上不起作用,因为情节提要没有 UITableViewCell NIB 文件(它集成到情节提要中)
我在我的项目中做什么
- 我创建对象并链接到我的插座属性
- 我使用 json 从互联网上获取数据。
- 我在tableview上显示它。
你可以在这里下载我的整个项目文件。这是 UITableview.m 中的代码cellForRowAtIndexPath
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell";
MyCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
NSDictionary *entry = [ _entries objectAtIndex:indexPath.row];
cell.boomTitle.text = [entry objectForKey:@"body"];
NSString *imageURL=[NSString stringWithFormat:@"http://kelnakub.co.cc/upload/%i.jpg",[[entry objectForKey:@"IdEntry"] intValue]];
for(NSDictionary *dic in _entries)
{
NewsFeed *myNewsFeed = [[NewsFeed alloc]init];
myNewsFeed.thumNail = [dic objectForKey:@"IdEntry"];
}
NSURL *url = [NSURL URLWithString:imageURL];
NSData *imageData = [NSData dataWithContentsOfURL:url];
cell.boomImage.image = [UIImage imageWithData:imageData];
cell.boomDate.text = [entry objectForKey:@"dateCreated"];
return cell;
}