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

所以基本上我是从一个数组中加载文本到表格视图中的单元格中,而不是像我想要的那样进入下一行,input的文本标签被切断了单个单元格中的屏幕。 我看上去在线,它说要设置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()方法中将tableview行高设置为UITableViewAutomaticDimension

 yourTableview.rowHeight = UITableViewAutomaticDimension yourTableview.estimatedRowHeight = 44 

要么

你可以在Controller中添加Bellow UITableViewDelegate方法

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