【发布时间】:2012-01-29 19:15:38
【问题描述】:
我有一个表格视图,后面有图像和文本,我创建如下代码的单元格:
- (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] autorelease];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
NSDictionary * companyProductRow = [DB getCompanyProductRow:[self.companyProductIDs objectAtIndex:indexPath.row]];
int companyProductID = [[companyProductRow objectForKey:@"ID"] intValue];
cell.tag = companyProductID;
cell.textLabel.text = [companyProductRow objectForKey:@"ImagePath"];
NSString* fullPath = [FileManager fullPath:companyProductID fairDirectory:[[self.currentFair objectForKey:@"ID"]intValue]];
[[cell imageView] setImage:[UIImage imageWithContentsOfFile:fullPath]];
return cell;
}
我在苹果开发者网站上阅读了一些关于 tableview 性能的提示,但他们都说: 重复使用细胞。对象分配有性能成本,特别是如果分配必须在短时间内重复发生 - 例如,当用户滚动表视图时。如果您重用单元格而不是分配新单元格,则可以大大提高表格视图的性能。 避免重新布局内容。当重用具有自定义子视图的单元格时,请避免在每次表格视图请求单元格时布置这些子视图。创建单元格时,布置一次子视图。 使用不透明的子视图。自定义表格视图单元格时,使单元格的子视图不透明,不透明。
apple 站点中的示例是相同的,但我想知道在 uitableview 上滚动时有什么方法可以提高性能吗? (当我们应该从磁盘读取图像时)。
谢谢
【问题讨论】:
标签: ios