美文网首页
解决快速滚动自定义UITableViewCell内存警告,程序闪

解决快速滚动自定义UITableViewCell内存警告,程序闪

作者: JakieZhang | 来源:发表于2016-11-05 10:07 被阅读113次

由于自定义tabelviewcell 老是重新创建,应该将cell重复用,复用可以减少内存,最重要的是else部分,代码如下:

if (!cell) {

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];

cell.accessoryType= UITableViewCellAccessoryNone;

cell.selectionStyle = UITableViewCellSelectionStyleNone;

}

else{//重要,释放cell,防止闪退方法,其他CustomCell均可沿用

while ([cell.contentView.subviews lastObject] != nil) {

[(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];

}

}

相关文章

网友评论

      本文标题:解决快速滚动自定义UITableViewCell内存警告,程序闪

      本文链接:https://www.haomeiwen.com/subject/hkxsuttx.html