我有一个带可折叠部分的tableView。在iOS 10或更早版本中,它可以完美地工作。但在iOS 11中,tableView的各个部分会创建浮动的区域标题,并在其他部分中间重复出现区域标题,如下所示:
我是一名有用的助手,可以为您翻译文本。
在我之前发布的另一个相关问题中,回答者建议预设估计高度如下:
这个修复了重复的部分,但是缩小了我的tableView单元格,使标签字段不再可见,而且单元格不能自动调整大小以显示其中所有的数据。
有报道称iOS 11改变了tableView高度的工作方式,采用了估算值。
我也尝试使用以下所有字段的估算值:
我一直在研究这个问题,这个问题已经在其他地方报道并讨论了在这里
这是我的tableView代码:
class CollapsibleTableViewController: UITableViewController {
var sections = sectionsData
override func viewDidLoad() {
super.viewDidLoad()
let tableView = UITableView.init(frame: CGRect.zero, style: .grouped)
// Auto resizing the height of the cell
tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension
self.title = "Education"
for index in 0 ..< sections.count {
sections[index].collapsed = true
}
}
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 44.0
}
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 1.0
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension //making this a fixed value fixes the drawing bug but doesn't let the cells autosize
}
在我之前发布的另一个相关问题中,回答者建议预设估计高度如下:
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
这个修复了重复的部分,但是缩小了我的tableView单元格,使标签字段不再可见,而且单元格不能自动调整大小以显示其中所有的数据。
有报道称iOS 11改变了tableView高度的工作方式,采用了估算值。
我也尝试使用以下所有字段的估算值:
tableView.rowHeight = UITableViewAutomaticDimension
tableView.sectionHeaderHeight = UITableViewAutomaticDimension
tableView.sectionFooterHeight = UITableViewAutomaticDimension
似乎没有一种方法可以既允许单元格正确自适应大小又防止单元格与浮动区段标题重复。
有什么想法可以解决这个问题吗?