底部行的可扩展 tableView 单元格可见问题?
Expandable tableView cell visible issue for bottom row?
我有 table 带有可扩展行的视图单元格,它工作正常。现在我遇到了 table 视图行的底部单元格何时展开但用户需要移动到 table 视图以查看可展开部分的问题。怎么做它会自动移动?
我认为您正在重新加载 expand/collapse 'tableView' 部分之后的部分。
您可以将 tableView 滚动到您正在展开的矩形部分。
例如:
let sectionRect = tableView.rect(forSection: section)
tableView.scrollRectToVisible(sectionRect, animated: false)
希望对您有所帮助!
最好使用 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)
}
})
我有 table 带有可扩展行的视图单元格,它工作正常。现在我遇到了 table 视图行的底部单元格何时展开但用户需要移动到 table 视图以查看可展开部分的问题。怎么做它会自动移动?
我认为您正在重新加载 expand/collapse 'tableView' 部分之后的部分。 您可以将 tableView 滚动到您正在展开的矩形部分。
例如:
let sectionRect = tableView.rect(forSection: section)
tableView.scrollRectToVisible(sectionRect, animated: false)
希望对您有所帮助!
最好使用 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)
}
})