通过单元格内textView的内容更改单元格高度 [英] Change cell height by the content of the textView inside the cell
本文介绍了通过单元格内textView的内容更改单元格高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为 todoTableView
的表视图,其中包含用户创建的单元格。
每个单元格都有文本视图。
我想根据文本视图的内容更改单元格的高度。
这就是我试过的:
I have a Table View called todoTableView
with cells that created by the user.
Each cell has Text View.
I want to change the height of the cell by the content of the Text View.
This is what I tried:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: TableViewCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath:indexPath) as! TableViewCell
cell.bounds.size.height = cell.textView.bounds.size.height
return cell
}
推荐答案
使用单元绑定
使用边际约束。(领先,尾随,顶部和底部约束) textview
来自各方的
- 禁用textView滚动
在 viewDidLoad()中添加以下内容。
tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension
这将根据textview内容大小调整单元格大小。
This will make your cell size according to your textview content size.
查看结果:
您无需编写 heightForRowAtIndexPath 。
这篇关于通过单元格内textView的内容更改单元格高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文