What is NSDiffableDataSourceSnapshot `reloadItems` for?

前端 未结 3 881
耶瑟儿~
耶瑟儿~ 2021-02-02 15:36

I\'m having difficulty finding the use of NSDiffableDataSourceSnapshot reloadItems(_:):

  • If the item I ask to reload is not equatable to an item that is already p

3条回答
  •  孤城傲影
    2021-02-02 16:00

    I posted the same question, not realising. I got this working by firstly converting my model to classes. Then calling 'applySnapshot' after calling 'reloadItems'.

    func toggleSelectedStateForItem(at indexPath: IndexPath, animate: Bool = true) {
        let item = dataSource.itemIdentifier(for: indexPath)!
        var snapshot = dataSource.snapshot()
        item.isSelected = !item.isSelected
        snapshot.reloadItems([item])
        dataSource.apply(snapshot)
    }
    

提交回复
热议问题