20160907, 用 model 传值, 返回 cell 的 高度

厉害

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 ;
    
    
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 2017.02.22 可以练习,每当这个时候,脑袋就犯困,我这脑袋真是神奇呀,一说让你做事情,你就犯困,你可不要太...
    Carden阅读 1,372评论 0 1
  • 我们在上一篇《通过代码自定义不等高cell》中学习了tableView的相关知识,本文将在上文的基础上,利用sto...
    啊世ka阅读 1,526评论 2 7
  • iOS网络架构讨论梳理整理中。。。 其实如果没有APIManager这一层是没法使用delegate的,毕竟多个单...
    yhtang阅读 5,242评论 1 23
  • *面试心声:其实这些题本人都没怎么背,但是在上海 两周半 面了大约10家 收到差不多3个offer,总结起来就是把...
    Dove_iOS阅读 27,200评论 30 471
  • 昨天跟妈妈打了个电话,这是开学两个月第一次往家里打电话。我妈高兴的问我什么时候放寒假,她买了好多苹果,等我回家。 ...
    微日迹阅读 264评论 0 0