如何让表格单元格中的标签继续下一行而不是被切断屏幕?(xcode 8)



所以基本上我正在将文本从数组加载到表格视图中的单元格中,但不是像我想要的那样继续下一行,而是输入的文本标签在单个单元格中被从屏幕上切断。我在网上看了一下,它说将 numberOfLines 设置为 0,将 lineBreakMode 设置为 NSLineBreakingByWordWrapping,但它不起作用。我做错了什么?谢谢!

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "homeSeries", for: indexPath)
    // Configure the cell...
    cell.textLabel?.text = dataArrayRelease[indexPath.row] + " " + dataArraySeries[indexPath.row] + " by " + dataArrayGroup[indexPath.row]
    cell.textLabel?.numberOfLines = 0
    cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping
    return cell
}

您的cellForRowAt方法代码是正确的。 你需要做一些与行高有关的东西。将表视图行高设置为viewDidLoad()方法中的UITableViewAutomaticDimension

yourTableview.rowHeight = UITableViewAutomaticDimension
yourTableview.estimatedRowHeight = 44

您可以在控制器中添加波纹管UITableViewDelegate方法

 func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        return 44
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }

最新更新