我试图在表格 View 单元格中包含一个标题和多行,但是该单元格没有扩展以适应“标题”和 3 行以适应那里。
这是我处理标题和 3 行的代码
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("deviceCell", forIndexPath: indexPath)
cell.textLabel?.text = "Title"
cell.detailTextLabel?.text = "Line1 " + "\n" + "Line2" + "\n" + "Line3"
return cell
}
这是我运行程序后的样子
最佳答案
添加这两个新方法有助于解决这个问题
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
关于ios - 无法在表格 View 单元格中容纳多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34890822/