【发布时间】:2019-08-09 16:57:58
【问题描述】:
我有一个管理两行数据的 TableView。每行都由一个 CollectionView 管理,它允许用户水平滚动并过滤数据。过滤器是表格视图的一部分,位于 CollectionView 之上。
这是一个视觉效果:
当我单击第一行的过滤器(上图中的屏幕外)时,用户界面会平滑地更新数据。但是,当我单击第二行的过滤器时,集合视图会短暂向上移动,然后再回到正确的位置。
我相当确信这个问题与我的界面构建器配置有关,但为了记录,这是重新加载集合视图的代码。
func onFetchCompleted() {
if shouldRefreshRow() {
//tableView.reloadData() // reload all rows
tableView.reloadRows(at: [IndexPath(row: viewModel!.rowToFetch!, section: 0)], with: .none)
}
}
func shouldRefreshRow() -> Bool {
return self.viewModel?.businessesStore[viewModel!.rowToFetch!].previousPage == 1
}
这是 TableView 配置:
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as? BusinessesTableViewCell {
cell.configureCell(dataSourceDelegate: self, filterDelegate: self, forPath: indexPath, indexPathsToReload:
return cell
}
return UITableViewCell()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if(viewModel?.businessesStore[collectionView.tag].businesses.count ?? 0 > 0) {
return (viewModel?.businessesStore[collectionView.tag].total)!
}
return 0
}
在界面构建器中,我将表视图的前导、尾随和底部约束设置为相对于超级视图为 0,相对于表视图上方的视图设置为顶部为 0(上图中的纯黑色)。
我相当肯定这是一个界面构建器问题,因为如果我移除底部约束并将我的 TableView 高度设置为 400 之类的值,则在单击过滤器时视图会正常运行。需要注意的是,用户必须向下滚动到屏幕底部,否则它会以上面解释的 janky 方式运行。
这是布局:
有什么想法吗?
【问题讨论】:
标签: ios uitableview uicollectionview