【发布时间】:2023-03-22 09:08:01
【问题描述】:
我正在开发一个应用程序,用户单击菜单项,tableView 应根据所选项目滚动。
但问题是collectionView在重新加载时闪烁了一下。
这里是可见部分。
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if let firstVisibleIndexPath = self.tblRestaurantFeed.indexPathsForVisibleRows?[0]{
self.tableViewVisibleSection = firstVisibleIndexPath.section
}}
当变量更新时,我正在重新加载集合视图并使用滚动到项目
var tableViewVisibleSection:Int = 0{
didSet{
UIView.animate(withDuration: 0.15, animations: {
self.collectionView.reloadData()
})
let visibleIndexPaths = collectionView.indexPathsForVisibleItems
let itemIndex = IndexPath(item: self.selectedTag, section: 0)
if(!visibleIndexPaths.contains(itemIndex)){
UIView.performWithoutAnimation {
self.collectionView.scrollToItem(at: IndexPath(item: self.selectedTag, section: 0), at: .centeredHorizontally, animated: true)
}
}
}}
任何帮助将不胜感激。
【问题讨论】:
-
那个蓝色的部分是表示Section吗? @Ranjan
-
顶部灰色背景是带有蓝色选中项的集合视图,其中“描述”显示的是 tableview 的节标题
-
你检查过这个answer吗?
标签: ios swift uitableview uicollectionview uicollectionreusableview