如何更改单元格高度以使UILabel适合?我没有在我的项目中使用自动布局。根据label.text更改TableViewCell高度?
另外,TableViewCell文本在cellForRowAtIndexPath
中设置。
代码:
var commentsArray: [String] = []
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:TableViewCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! TableViewCell;
if self.commentsArray.count > indexPath.row{
cell.commentsText.text = commentsArray[commentsArray.count - 1 - indexPath.row]
cell.commentsText.font = UIFont.systemFontOfSize(15.0)
}
return cell
}
任何想法?
看看http://stackoverflow.com/questions/19215199/dynamically-size-uitableviewcell-according-to-uilabel-with-paragraph-spacing – Hamish
@ originaluser2问题是文本已经在那里设置,我的是来自查询。 –
'heightForRowAtIndexPath'在'cellForRowAtIndexPath'后被调用,那么问题是什么?只需在'cellForRowAtIndexPath'中计算文本大小并将其返回到'heightForRowAtIndexPath'。 – Hamish