厉害
20160907, 用 model 传值, 返回 cell 的 高度
EssenceModel.h
#import <JSONModel/JSONModel.h>
@interface ListModel : JSONModel
//@property (nonatomic, assign) CGFloat cellHeight;//后来 增加 , 与 JSONModel 相冲突
//@property (nonatomic, assign) NSNumber<Optional> * cellHeight; 这样 是 错的, 会崩溃的。 不能用 assign.
@property (nonatomic, strong) NSNumber<Optional> * cellHeight;
@end
EssenceVideoCell.m
- (void) setModel: (ListModel *) model {
[self layoutIfNeeded ]; //强制 cell 刷新, 也就是 按照数据, 全部显示 一次 cell.
if (!model.top_comment){
self.commentViewHCon.constant = 0;
self.commentViewYCon.constant = 0;
self.commentView.hidden = YES;
}else {
NSString * commentStr = [ NSString stringWithFormat: @"%@: %@", model.top_comment.u.name, model.top_comment.content ];
self.commentView.hidden = NO;
self.commentLabel.text = commentStr;
self.commentViewYCon.constant = 14;
self.commentViewHCon.constant = self.commentLabel.height + 8;
}
NSLog(@"%lf", CGRectGetMaxY(self.loveButton.frame));
model.cellHeight = @(CGRectGetMaxY(self.loveButton.frame) + 10); //加 @ , 转化为 对象。
// 看这里
}
EssenceTableViewController.m
@implementation EssenceTableViewController
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
ListModel * model = self.dataModel.list[indexPath.row];
NSLog(@"%s", __func__);
//NSLog(@"%lf", model.cellHeight.floatValue);
return model.cellHeight.floatValue ;
}