我在故事板中的tableviewcell中遇到了UIImage問題。 當我在tableview中滾動單元格時,它每次都要求服務器發送數據,所以單元格很慢。 我看過這個video ,但它不能在故事板工作,因爲故事板donesn't有UITableViewCell的NIB文件(其集成到故事板)如何將UIImage插入到UITableViewCell中
我在我的項目做什麼
- 我創建對象並鏈接到我的插座屬性
- 我使用json從互聯網上獲取數據。
- 我在桌面上顯示它。
您可以下載我的整個項目文件here。這是代碼在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;
}