底部行的可扩展tableView单元可见问题?

时间:2019-05-24 09:50:55

标签: swift uitableview expandablelistview

我有带有可扩展行的tableview单元,其工作正常。现在,我有一个问题,即表格视图行的底部单元格何时会展开,但用户需要移至表格视图才能查看可扩展部分。它将如何自动移动? enter image description here

2 个答案:

答案 0 :(得分:0)

我认为您在展开/折叠“ tableView”部分后正在重新加载该部分。 您可以将tableView滚动到要扩展的区域。

例如:

let sectionRect = tableView.rect(forSection: section)
tableView.scrollRectToVisible(sectionRect, animated: false)

希望这会有所帮助!

答案 1 :(得分:0)

最好使用func scrollRectToVisible(_ rect: CGRect, animated: Bool),如果该部分可见,则此方法不会滚动表视图。您可以使用此方法func rect(forSection section: Int) -> CGRect

轻松获得正确的区域

示例:

tableView.performBatchUpdates({ [weak tableView] in
        tableView?.insertRows(at: indexPaths, with: .fade)
 }, completion: { [weak tableView] _ in
        if let sectionRect = tableView?.rect(forSection: section) {
             tableView.scrollRectToVisible(sectionRect, animated: true) 
        }
 })