iOS11中扭曲的tableview部分-UITableViewAutomaticDimension问题
我有一个可折叠部分的桌面视图。在iOS 10或更早版本中,它可以完美地工作。在IOS 11中,TabLVIEW部分在其他部分的中间创建浮动节头和重复节头,如图所示: 我一直在研究这个问题,其他地方也有报道和讨论 以下是我的tableView代码:iOS11中扭曲的tableview部分-UITableViewAutomaticDimension问题,ios,swift,uitableview,ios11,Ios,Swift,Uitableview,Ios11,我有一个可折叠部分的桌面视图。在iOS 10或更早版本中,它可以完美地工作。在IOS 11中,TabLVIEW部分在其他部分的中间创建浮动节头和重复节头,如图所示: 我一直在研究这个问题,其他地方也有报道和讨论 以下是我的tableView代码: class CollapsibleTableViewController: UITableViewController { var sections = sectionsData override func viewDidLoad
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
}
这修复了重复部分,但缩小了“我的tableView”单元格,因此标签字段不再可见,单元格也不会自动调整大小以显示其中的所有数据
据报道,iOS 11通过使用估计值改变了tableView高度的工作方式
我还尝试对所有字段使用估计值,如下所示:
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
tableView.rowHeight = UITableViewAutomaticDimension
tableView.sectionHeaderHeight = UITableViewAutomaticDimension
tableView.sectionFooterHeight = UITableViewAutomaticDimension
无论是允许单元格的适当自动调整大小,还是防止单元格与浮动节头重复,似乎都不起作用
有关如何解决此问题的任何想法?在视图中将出现()
编写tableViews初始值,然后提供UItableViewAutomaticDimension,如下所示:
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
tableView.rowHeight = UITableViewAutomaticDimension
tableView.sectionHeaderHeight = UITableViewAutomaticDimension
tableView.sectionFooterHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight=75
tableView.rowHeight=UITableViewAutomaticDimension
根据需要对页眉、页脚等进行冲洗和重复操作。您能在GitHub上发布一个包含此内容的项目,以便我查看它吗?我有一个小时的空闲时间,我想了解并可能解决这个问题。在iOS 10上,您的表将使用自调整大小的单元格以及固定大小的页眉和页脚。在iOS 11上,表使用自调整大小的单元格、页眉和页脚。尝试将
estimatedSectionHeaderHeight
和estimatedSectionFooterHeight
设置为零,以返回固定大小的页眉和页脚。其他一切都保持不变。@Darren-我试过了,但遗憾的是没有用。仍然得到重复的标题部分。是的!!非常感谢。将其移动到ViewWillIspect而不是viewDidLoad似乎解决了问题。