ios – 通过单元格内textView的内容更改单元格高度
发布时间:2020-12-15 01:47:24 所属栏目:百科 来源:网络整理
导读:我有一个名为todoTableView的表视图,其中包含由用户创建的单元格. 每个单元格都有文本视图. 我想通过文本视图的内容更改单元格的高度. 这是我试过的: func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) - UITableViewC
我有一个名为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 } 解决方法
使用边际约束从所有边使用单元格绑定您的textview.(前导,尾随,顶部和底部约束)
>禁用textView滚动 在viewDidLoad()中添加以下内容. tableView.estimatedRowHeight = 44.0 tableView.rowHeight = UITableViewAutomaticDimension 这将根据您的textview内容大小制作单元格大小. 看看结果: 您不需要编写heightForRowAtIndexPath. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |