调整 UITableViewCell 的高度

Resizing UITableViewCell height

我很难调整 .toDoListTable 中单元格的 .rowHeight 大小。从 UITextfield 接收到的字符串在每一行的末尾被截断。 我在设置原型单元格时没有添加标签,因为我的字符串是从 UITextField 附加的。我的代码如下:

override func viewDidLoad() {
    super.viewDidLoad()


        toDoListTable.estimatedRowHeight = 45.0

        toDoListTable.rowHeight = UITableViewAutomaticDimension


    }

}

但是,我的文字仍然被截断。有什么建议么?另外,我的代码在正确的位置吗?

我希望让我的内容适应 UITextField 提供的文本量。

编辑:通过添加 cell.textLabel?.numberOfLines = 0.

解决了问题

使用它来设置行的高度:

override func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat
    {
         return 50 //your height
    }

文档:

https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/index.html

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat{
    return 30 // height you want to set.
}

我知道我迟到了,但我想正确回答我自己的问题。

我只是添加了:cell.textLabel?.numberOfLines = 0cellForRowAtIndexPath 函数以允许多行不受限制的文本。