在項(xiàng)目中 使用tableView比較多,cell的高度有的時(shí)候不是固定的,所以需要根據(jù)模型計(jì)算高度晋柱,為了考慮效率和代碼易讀,我們把cell上控件的frame 封裝到模型中诵叁,
1趣斤、給所有控件的frame
2、cell的高度黎休;
@interface HLCellModel : NSObject
//****** frame *******
/**
* 文字 圖片數(shù)據(jù)
*/
@property(nonatomic,assign)CGRect iconFrame;
/**
* cell高度
*/
@property(nonatomic,assign) float cellHeight;
@end
@implementation HLCellModel
//重寫模型cellHeight屬性的get方法
-(float)cellHeight
{
if (_cellHeight == 0) {
// ...計(jì)算所有子控件的frame cell的高度
}
return _cellHeight;
}
@end
//在tableview上使用
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
HLCellModel * cellModel = [self.dataSourceArray objectAtIndex:indexPath.row];
return cellModel.cellHeight;
}