如何解决带有选定单元格的奇怪的 tableview 单元格行为
所以我有一个使用 diffible 数据的 tableview,当我选择一个单元格然后滚动到 tableview 的顶部时,所选单元格将自身定位在 tableview 的顶部。
extension RunScenarioViewController: NSFetchedResultsControllerDelegate {
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>,didChangeContentWith snapshot: NSDiffableDataSourceSnapshotReference) {
var diffableDataSourceSnapshot = NSDiffableDataSourceSnapshot<Int,Event>()
diffableDataSourceSnapshot.appendSections([0])
diffableDataSourceSnapshot.appendItems(fetchedResultsController.fetchedObjects ?? [])
datasource?.apply(diffableDataSourceSnapshot,animatingDifferences: view.window != nil)
}
extension RunScenarioViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView,didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) as! EventTableViewCell
cell.roundView.layer.borderColor = UIColor.darkYellow.cgColor
let event = cell.event
selectedEvent = event
if event?.image != nil {
controller?.loadImage(summary: nil,scenario: scenario,event: event,completion: { image in
DispatchQueue.main.async {
self.eventImage.image = image
self.imageInfoButton.tintColor = UIColor(named: "YellowColor")
}
})
} else {
eventImage.image = nil
self.imageInfoButton.tintColor = .clear
}
}
func tableView(_ tableView: UITableView,didDeselectRowAt indexPath: IndexPath) {
if let cell = tableView.cellForRow(at: indexPath) as? EventTableViewCell {
cell.roundView.layer.borderColor = UIColor.clear.cgColor
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。