NCF*_*USN 2 iphone uitableview ios
使用:
每个单元格上都有1个图像和文本.滚动时图像不会调整大小.有两个版本的images image.png和image@2x.png.
通过在故事板中使用UIImageView和UILabel来管理自定义单元格.
码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
Continent *continent=[self.items objectAtIndex:[indexPath row]];
ContinentCell *cell = (ContinentCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.continentName.text=continent.continentName;
cell.textView.text=continent.countriesHash;
cell.imageView.image=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:continent.continentImage ofType:@"png"]];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
邪恶在哪里?先感谢您.
lor*_*ean 12
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:continent.continentImage ofType:@"png"]];
Run Code Online (Sandbox Code Playgroud)
太贵了.您希望在后台异步加载图像,然后在准备好时将其显示在主线程上.
这是一个非常粗略的解决方案
cell.imageView.image = nil;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIImage * img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:continent.continentImage ofType:@"png"]];
dispatch_sync(dispatch_get_main_queue(), ^{
cell.imageView.image = img;
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5604 次 |
| 最近记录: |