autolayout在cell高度变化中的应用(下)

有了autolayout,咱们彻底能够用xib去布局cell上的子空间,不用再去写冗余的建立代码及frame模型。布局

本身仅仅须要作的是:拿到cell最下面固定的子控件(一直存在),在返回高度的方法中,写以下代码便可it

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HomePageCell *cell = [tableView dequeueReusableCellWithIdentifier:kHomePageCell];

    HomePageCellModel *model = self.dataList[indexPath.row];
    cell.homePageCellModel = model;
    
    [cell layoutIfNeeded];
    return cell.locationContainer.y + cell.locationContainer.height + 13 + 13;
}io

使用注意:若是label是多行的必定要设置preferredMaxLayoutWidth,若是存在多个多行label,都要设置,这样才能获得正确的布局table

相关文章
相关标签/搜索