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

标签 swift dynamic ios8 resize tableview

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/

相关文章:

ios - Xcode 的两个选项卡之间的共享变量

image - WordPress 查询帖子获取图像除非空白

PostgreSQL 交叉表查询从辅助查询中提取列

iOS 8 beta 5 Game Center Sandbox 无法识别我的应用

点击后退按钮时,iOS 8 屏幕滑动方向错误

ios - 使用 Swift 解析 tableview 中的 Json

ios - 从另一个 View 访问 ViewController 的 ScrollView

Swift Biginteger xor 加密/解密

c# - 动态文本框在asp.net中添加按钮单击和数据 session

iOS 8 在不安装 Xcode 的情况下从用户设备读取控制台日志