【发布时间】:2016-09-02 16:14:17
【问题描述】:
如何更改单元格高度以使 UILabel 适合?我没有在我的项目中使用自动布局。
另外,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
}
有什么想法吗?
【问题讨论】:
-
@originaluser2 问题是文本已经设置在那里,我的来自查询。
-
heightForRowAtIndexPath在cellForRowAtIndexPath之后被调用,那么问题出在哪里?只需计算cellForRowAtIndexPath中的文本大小并在heightForRowAtIndexPath中返回它们。 -
@originaluser2 怎么样?
标签: ios swift uitableview