gpt4 book ai didi

ios - 自定义 UITableViewCells 在表中重叠

转载 作者:行者123 更新时间:2023-11-29 01:13:54 28 4
gpt4 key购买 nike

我有一个自定义单元格:

enter image description here

但是当 tableView 加载时,我在其中有重叠的单元格:

enter image description here

我尝试将以下代码插入到我的 viewDidLoad() 中:

tableView.estimatedRowHeight = tableView.rowHeight
tableView.rowHeight = UITableViewAutomaticDimension

但这并没有帮助。

最佳答案

来自文档:

//Declaration
//SWIFT
optional func tableView(_ tableView: UITableView,
heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
//OBJECTIVE-C
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath

使该方法返回单元格的高度。如果这没有帮助,那么您需要向我们提供更多详细信息(可能还有限制条件)。

编辑:我设法通过做两件事来解决这个问题:

  1. 更改这两行:

    tableView.estimatedRowHeight = 150

    tableView.rowHeight = UITableViewAutomaticDimension

tableview 会自动缩小单元格

  1. 在单元格 xib 中,您应该将约束添加到单元格的底部。这样就可以正确计算出高度。

如果你想要我可以给你一个项目的工作副本,只需提供一些联系邮件或其他东西。

关于ios - 自定义 UITableViewCells 在表中重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35451064/

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