gpt4 book ai didi

swift - iOS8 Swift - 动态调整 tableview 单元格大小的问题

转载 作者:行者123 更新时间:2023-11-28 07:12:40 25 4
gpt4 key购买 nike

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: 函数。使用它,您可以单独设置每一行的高度。

更多信息:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/index.html#//apple_ref/occ/intfm/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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com