Here's what my application looks like currently.
您会看到当字幕文本标签只有一行时可以正确调整大小,但是当有多行时它会变得一团糟。我认为这可能与约束有关?现在我正在使用自动布局约束。您可以在屏幕截图中看到它们。这是创建我的单元格的代码。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> DealCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Deal Cell", forIndexPath: indexPath) as DealCell
let currentBar = bars[indexPath.row] as BarAnnotation
cell.barName.text = currentBar.name
cell.deal.text = currentBar.deal
cell.distanceToBar.text = String(format: "%.3f mi", currentBar.distance)
// Set the height of the table view cells
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 44.0;
return cell
}
有什么想法吗?
最佳答案
在 UITableViewDelegate 中使用 tableView:heightForRowAtIndexPath:
函数。
使用它,您可以单独设置每一行的高度。
或者您可以使用本文中的自动布局设置。 http://useyourloaf.com/blog/2014/02/14/table-view-cells-with-varying-row-heights.html
关于swift - iOS8 Swift - 动态调整 tableview 单元格大小的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27752971/