1

我有一个带有一个 TableView 的 TableViewController,它的行通过自动布局动态设置。

我在控制器中添加了另一个用于菜单的 TableView。它的行高需要设置为 65。

问题在于heightForRowAtIndexPath。我知道如何只为这个 tableView 菜单的行返回 65。但我不确定如何让自动布局为另一个 tableView 做这件事。

有谁知道我怎么能做到这一点?

这是我的代码:

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if tableView is YALContextMenuTableView {
        return 65
    } else {

    }
}
4

2 回答 2

6

您可以通过super以下方式使用此方法的实现UITableViewController

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if tableView is YALContextMenuTableView {
        return 65
    } else {
        return super.tableView(tableView, heightForRowAtIndexPath:indexPath)
    }
}
于 2015-09-02T17:47:49.490 回答
2
  • 不要使用tableView:heightForRowAtIndexPath:. 为您的菜单 tableView 单元格调整自动布局和自动调整大小,因此它的约束调整其高度(到 65),或者

  • 继续使用tableView:heightForRowAtIndexPath:UITableViewAutomaticDimension返回非菜单 tableView 单元格的高度,这将让系统自行调整这些单元格的大小。

自调整大小将是首选方式,因为它与动态类型和自适应 UI 结合使用效果很好。

于 2015-09-02T17:47:59.837 回答