我正在尝试优化应用程序中的负载,实际上,我的应用程序中已经加载了很多图像,并且我花了很多时间等待 View Controller 打开,尤其是包含大量内容的第一个初始 View 图片。
我看了apple sample
但是我不能重做整个应用程序,我只想告诉我该怎么做?我实现了吗?
在tableview
中,实现单元格的位置cellforrowatindexpath:
NSURL *imageURL = ......;
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *imageLoad;
imageLoad = [[UIImage alloc] initWithData:imageData];
imageView.image = imageLoad;
我可以做点什么吗?
感谢您的帮助!
最佳答案
是的,您可以向其中添加占位符图像。
它不会减慢滚动速度,并且会随着时间加载图像。
还导入此文件 UIImageView + WebCache.m 和 MapKit 框架
Here is the link下载文件。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
UIImageview* iV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
[iV setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"image_placeholder.gif"]];
[cell.contentView addSubview:iV];
[iV release];
}
只是清洁,构建和运行。