ios - 自动尺寸不起作用

标签 ios swift uitableview autolayout

我希望单元格能够拉伸(stretch)以适合标签中的内容。

类(class):

class TestTableController: UITableViewController {

  @IBOutlet weak var titleLabel: UILabel!

  @IBOutlet weak var mainLabel: UILabel!

  @IBOutlet weak var nameField: HoshiTextField!

  @IBOutlet weak var requestButton: UIButton!

  override func viewDidLoad() {
    super.viewDidLoad()

    tableView.estimatedRowHeight = 44
    tableView.rowHeight = UITableViewAutomaticDimension
  }

  override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath.row == 1 {//<- only for this row
      return UITableViewAutomaticDimension
    }
    return super.tableView(tableView, heightForRowAt: indexPath)
  }


  @IBAction func requestButtonTapped(_ sender: UIButton) {
    //TODO
  }
}

限制:

enter image description here

enter image description here

(superview是contentView,我仔细检查过)

结果(单元格是 lorem ipsum):

enter image description here

行数设置为零:

enter image description here

编辑:已解决。完全没有改变任何东西,甚至没有清理就进行了新的构建,现在它可以工作了...=.=

最佳答案

将文本类型设置为归因 enter image description here

关于ios - 自动尺寸不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44588298/

相关文章:

ios - UITableViewCell 的动态高度无法正常工作

ios - 当我们将一个 View Controller 导航到另一个 View Controller 时,这之间有什么不同

使用 Parse 进行 iOS 开发 : "Forgot password" button outcome

iphone - UITableView 动态添加单元格

ios - 以编程方式快速将搜索栏添加到 TableView

ios - 如何使用 iOS CoreBluetooth 从 dex 无线适配器检索 DEX?

ios - 如何在 iOS 上与 XMPP 断开连接?

ios - 如何在 UITableViewCell 中处理 AVPlayer?

swift - 删除一对多关系

ios - 创建自定义 UITableView 分隔线