【发布时间】:2021-03-28 02:56:07
【问题描述】:
我有一个tableView 和两个cells,代码如下:
viewModel.content.bind(to: tableView.rx.items) { _, _, item in
return self.cellFactory(item: item)
}.disposed(by: disposeBag)
func cellFactory(item: Any) -> UITableViewCell {
if let cellViewModel = item as? StaticSupportTableViewCellViewModel {
guard let cell = tableView.dequeueReusableCell(withIdentifier: StaticSupportTableViewCell.identifier) as? StaticSupportTableViewCell else { return UITableViewCell() }
cell.viewModel = cellViewModel
cell.isHidden = true
return cell
} else if let cellViewModels = item as? SupportTableViewCellViewModel {
guard let cell = tableView.dequeueReusableCell(withIdentifier: SupportTableViewCell.identifier) as? SupportTableViewCell else { return UITableViewCell() }
cell.viewModel = cellViewModels
return cell
} else { return UITableViewCell() }
}
现在,我想隐藏第一个单元格并写cell.isHidden = true。虽然这确实隐藏了单元格,但它仍然占用了不可见的空间,将另一个 cell 向下推。如何让它完全消失?我试过cell.removeFromSuperView() 但没有运气。我还尝试使用estimatedHeightForRowAt 委托和单元格本身设置高度。
【问题讨论】:
-
我在任何地方都没有看到 cell.isHidden = true。
-
我后来添加它只是为了测试,它没有工作:) 这是标准代码。
-
声明要在函数外部删除的单元格变量(不让),然后再次尝试将其从超级视图中删除。
标签: ios swift uitableview tableview show-hide