設(shè)置 UITableView iOS 8 的 Self Sizing Cells 屬性
_tableView.rowHeight = UITableViewAutomaticDimension;
_tableView.estimatedRowHeight = 44.0f;
注意,設(shè)置了
_tableView.rowHeight = UITableViewAutomaticDimension;之后就不要實(shí)現(xiàn)tableView: heightForRowAtIndexPath:方法了,如果實(shí)在要設(shè)置,應(yīng)該在需要自動(dòng)計(jì)算高度的row返回 UITableViewAutomaticDimension(否則自動(dòng)計(jì)算高度會(huì)失效)
設(shè)置 UITextView 的 Masonry 布局
[self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.bottom.mas_equalTo(self.contentView);
make.height.mas_greaterThanOrEqualTo(44);
}];
注意,需要設(shè)置左右上下的約束,且設(shè)置高度大于或等于一個(gè)固定的數(shù)值
在文本輸入時(shí)讓 UITableView 改變行高
在 textViewDidChange: 時(shí)給 tableView 一個(gè)回調(diào),執(zhí)行
@weakify(tableView);
cell.updateHeight = ^{
@strongify(tableView);
[tableView beginUpdates];
[tableView endUpdates];
};