Eli*_*iko 8 iphone xcode uitableview ios swift
我有一个表格视图,todoTableView其中包含由用户创建的单元格.每个单元格都有文本视图.我想通过文本视图的内容更改单元格的高度.这是我试过的:
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
}
Run Code Online (Sandbox Code Playgroud)
Irf*_*fan 24
绑定您textview与cell来自四面八方的使用边际约束.(前置,顶部和底部的约束)
在viewDidLoad()中添加以下内容.
tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension
Run Code Online (Sandbox Code Playgroud)
这将根据您的textview内容大小制作单元格大小.
看看结果:
您不需要编写heightForRowAtIndexPath.
| 归档时间: |
|
| 查看次数: |
9207 次 |
| 最近记录: |