如何解决设置backgroundView的性能更好:willDisplayCell还是init?
| 我只是很好奇,设置UITableViewCell的自定义backgroundView有什么更好的性能? 选项0)UITableViewCell初始化方法的子类@implementation CustomCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier andReleases:(NSArray*)releases {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@\"tablecell.png\"]] autorelease];
}
return self;
}
选项1)willDisplayCell委托方法
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@\"tablecell.png\"]] autorelease];
}
解决方法
在这种情况下,选项0更好,因为在创建单元格时将背景设置一次,每次显示单元格时将设置
willDisplayCell
。而且由于您将重复使用UITableViewCells
,因此可以减少创建单元格的时间,然后将其显示出来。
但是请避免过早的优化,仅在感觉性能不够好时才进行优化。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。