您不需要 cellForRowAtIndexPath 中的某些代码,最好在 IB 或单元代码中设置 numberOfLines。我将 cellForRowAtIndexPath 更改为如下,并在单元格中添加代码如下,
在 cell.m 中,
override func didMoveToSuperview() {
self.titleLabel.numberOfLines = 0
self.subTitleLabel.numberOfLines = 0
self.layoutIfNeeded()
}
在 cellForRowAtIndexPath 中,
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as MyCell
let content = self.data[indexPath.row]
cell.titleLabel.text = content.line1
cell.subTitleLabel.text = content.line2
return cell;
}
如果单元格代码中没有 layoutIfNeeded,当显示第二个表格时,我没有看到任何扩展行——仅在滚动或旋转之后。有了它,一切似乎都很好。