仅为一个 tableView 设置行高并忽略 heightForRowAtIndexPath 中的其他 tableView?
Set row height for only one tableView and ignore other tableView's in heightForRowAtIndexPath?
我有一个带有一个 TableView 的 TableViewController,它的行通过 自动布局动态设置。
我已将另一个 TableView 添加到用于菜单的控制器。它的行高需要设置为 65。
问题是,在 heightForRowAtIndexPath 中。我知道如何为这个 tableView 菜单的行设置 return 65。但我不确定如何让 自动布局 为另一个 tableView 做这件事。
有谁知道我该怎么做?
这是我的代码:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if tableView is YALContextMenuTableView {
return 65
} else {
}
}
您可以使用super
通过UITableViewController
使用此方法的实现:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if tableView is YALContextMenuTableView {
return 65
} else {
return super.tableView(tableView, heightForRowAtIndexPath:indexPath)
}
}
不要使用 tableView:heightForRowAtIndexPath:
。为您的菜单 tableView 单元格调整自动布局和自动调整大小,因此其约束调整其高度(至 65),或
继续使用tableView:heightForRowAtIndexPath:
。 Return 非菜单 tableView 单元格的高度 UITableViewAutomaticDimension
,这将使系统自行调整这些单元格的大小。
自动调整大小将是首选方式,因为它与动态类型和自适应结合使用效果很好UI。
我有一个带有一个 TableView 的 TableViewController,它的行通过 自动布局动态设置。
我已将另一个 TableView 添加到用于菜单的控制器。它的行高需要设置为 65。
问题是,在 heightForRowAtIndexPath 中。我知道如何为这个 tableView 菜单的行设置 return 65。但我不确定如何让 自动布局 为另一个 tableView 做这件事。
有谁知道我该怎么做?
这是我的代码:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if tableView is YALContextMenuTableView {
return 65
} else {
}
}
您可以使用super
通过UITableViewController
使用此方法的实现:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if tableView is YALContextMenuTableView {
return 65
} else {
return super.tableView(tableView, heightForRowAtIndexPath:indexPath)
}
}
不要使用
tableView:heightForRowAtIndexPath:
。为您的菜单 tableView 单元格调整自动布局和自动调整大小,因此其约束调整其高度(至 65),或继续使用
tableView:heightForRowAtIndexPath:
。 Return 非菜单 tableView 单元格的高度UITableViewAutomaticDimension
,这将使系统自行调整这些单元格的大小。
自动调整大小将是首选方式,因为它与动态类型和自适应结合使用效果很好UI。