我正在尝试使用trailingSwipeActionsConfigurationForRowAt函数从UITableView中删除行。
该行将被删除并消失。这部分没问题。
但是,下一行将要出现在屏幕上,或者当我向下滑动与删除的行相同数量的行时,甚至不会加载到tableView上。
(https://poirot.deus4.com/photo_2019-06-12_16-44-01.jpg)
(https://poirot.deus4.com/photo_2019-06-12_16-43-56.jpg)
(https://poirot.deus4.com/photo_2019-06-12_16-43-49.jpg)
(https://poirot.deus4.com/photo_2019-06-12_16-43-38.jpg)
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return filteredProducts.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: .cellID, for: indexPath) as! ProductTableCell
cell.backgroundColor = .red
return cell
}
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let hide = UIContextualAction(style: .destructive, title: "Hide") { action, view, completion in
self.filteredProducts.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .automatic)
completion(true)
}
hide.image = #imageLiteral(resourceName: "hdie_product")
hide.backgroundColor = .midGrey
let conf = UISwipeActionsConfiguration(actions: [hide])
return conf
}
https://stackoverflow.com/questions/56563828
复制相似问题