底行的可扩展 tableView 单元格可见问题?
Posted
技术标签:
【中文标题】底行的可扩展 tableView 单元格可见问题?【英文标题】:Expandable tableView cell visible issue for bottom row? 【发布时间】:2019-05-24 09:50:55 【问题描述】:我有带有可扩展行的表格视图单元格,它工作正常。现在我遇到了表格视图行的底部单元格何时展开但用户需要移动到表格视图以查看可展开部分的问题。怎么办它会自动移动?
【问题讨论】:
您好,您可以添加您所面临问题的代码和图片吗? @Let's_Create 我用图片更新我的问题 尝试 tblVw.scrollToRow(at: IndexPath(row: (sender.view?.tag)!, section: 0), at: .bottom, 动画: true) 【参考方案1】:我认为您在展开/折叠“tableView”部分后重新加载该部分。 您可以将 tableView 滚动到您正在扩展的部分 rect。
例如:
let sectionRect = tableView.rect(forSection: section)
tableView.scrollRectToVisible(sectionRect, animated: false)
希望这会有所帮助!
【讨论】:
如何达到行数 tableView.scrollToRow(at: IndexPath) DispatchQueue.main.async tableView.scrollToRow(at: lastIndexPath, at: .bottom, animated: true) DispatchQueue.main.async tableView.scrollToRow(at: lastIndexPath, at: .bottom, animated: true) 它的工作就像魅力【参考方案2】:最好使用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)
)
【讨论】:
以上是关于底行的可扩展 tableView 单元格可见问题?的主要内容,如果未能解决你的问题,请参考以下文章
tableView:cellForRowAtIndexPath:不仅为可见单元格调用吗?
TableView 的屏幕截图不仅适用于可见单元格,而且适用于所有可用单元格