做网站的dw全称是啥,适合迷茫年轻人的工作,优舟网站建设,东莞市火速网络科技有限公司由于tableView:heightForRowAtIndexPath:方法的调用频率非常高#xff0c;如果将cell高度的计算过程放在此方法中#xff0c;那么效率将会非常的低#xff0c;快速tableview就会出现卡顿 1、通过代码 (在模型当中只计算一次cell高度#xff0c;然后在方法中直接从模型属性当…由于tableView:heightForRowAtIndexPath:方法的调用频率非常高如果将cell高度的计算过程放在此方法中那么效率将会非常的低快速tableview就会出现卡顿 1、通过代码 (在模型当中只计算一次cell高度然后在方法中直接从模型属性当中取出cell高度) #import UIKit/UIKit.hinterface CellItem : NSObject/**cell高度*///表明不能在外部修改
property (nonatomic, assign,readonly) CGFloat cellHeight;end #import CellItem.hinterface CellItem()
{CGFloat _cellHeight;//使用了readonly策略又实现了getter方法编译器将不再生成_cellHeight成员变量需要手动添加
}
endimplementation CellItem- (CGFloat)cellHeight
{if (!_cellHeight)//保证只计算一次{_cellHeight /**计算cell高度*/}return _cellHeight;
}end 2、通过自动布局自动计算 - (void)viewDidLoad {[super viewDidLoad];self.myTableView.estimatedRowHeight 44;self.myTableView.rowHeight UITableViewAutomaticDimension;
}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{return UITableViewAutomaticDimension;
} 转载于:https://www.cnblogs.com/HJQ2016/p/5928820.html