UITableView 自动尺寸无法正常工作 [英] UITableView Automatic Dimension Not Working Correctly

查看:21
本文介绍了UITableView 自动尺寸无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 tableview,其中填充了来自 Firebase 的数据.但是,当使用自动尺寸调整 tableview 大小时,一些文本会被截断.

I have a tableview that is getting populated with data from Firebase. However, when resizing the tableview using automatic dimension, some text is shown getting cut off.

这是我的故事板,约束设置为顶部、底部、右侧和左侧.

Here is my Storyboard with constraints set to top, bottom, right, and left.

当这里显示的文本不多时,它工作正常.

It is working fine when there is not alot of text as shown here.

但是,当我用大量文本填充单元格时,就会发生这种情况.

However, when I fill the cell with alot of text this occurs.

这是我目前使用的代码.

Here is the code that I am currently using.

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if (tableView == questInformationTableView) {
            return 50
        }
        else if (tableView == questWalkthroughTableView) {

            return UITableView.automaticDimension
        }

        return 0
    }
    override func viewDidLoad() {
          super.viewDidLoad()
          questWalkthroughTableView.estimatedRowHeight = 250
          questWalkthroughTableView.rowHeight = UITableView.automaticDimension
        }

    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
         return UITableView.automaticDimension
        }

我还将 numberOfLines 设置为 0 并将标签设置为 .sizeToFit()

I have also set numberOfLines to 0 and set the label to .sizeToFit()

推荐答案

建议检查

  1. 在表格单元格内启用自动行高

  1. automatic row height is enabled inside the table cell

检查标签是否可展开并且其底部约束设置为超级视图.添加屏幕截图,显示我正在使用动态高度的示例单元格的约束列表.

check if the label is expandable and its bottom constraint is set to superview. Adding screenshot showing list of constraints of a sample cell I am using with dynamic height.

  1. 即使这不能解决您的问题,也建议重置所有约束并为您的单元重新设置.

这篇关于UITableView 自动尺寸无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆