我在单元格中有一个自定义按钮,可以从可观察列表中删除项目。
self.searchListViewModel.genericList.value.remove(at: index)
所有逻辑都运行良好,但我需要一个动画来删除cell.Something like this
self.tableView.deleteRows(at: [IndexPath(row: index, section: 0)],
with: .fade)
但是现在,如果我尝试同时使用它们,应用程序会崩溃。
答案 0 :(得分:1)
抱歉延误。以下是rxswift中可动画表视图的示例。
enum MySectionItem {
case a(presentable: APresentable)
case b(presentable: BPresentable)
case c(presentable: CPresentable)
}
extension MySectionItem: IdentifiableType, Equatable {
typealias Identity = String
var identity: Identity {
switch self {
case let .a(presentable):
return presentable.title //Something which can define uniqueness
case let .b(presentable):
return presentable.title
case let .c(presentable):
return presentable.title
}
}
}
对于SectionModel,您也可以这样做。
enum MySectionModel {
case a(title: String, items: [MySectionItem])
case b(title: String, items: [MySectionItem])
case c(title: String, items: [MySectionItem])
}
extension MySectionModel: AnimatableSectionModelType {
typealias Item = MySectionItem
var items: [Item] {
switch self {
case let .a(title: _, items: items),
let .b(title: _, items: items),
let .c(title: _, items: items):
return items.map { $0 }
}
}
var identity: String {
switch self {
case let .a(title: title, items: _),
let .b(title: title, items: _),
let .c(title: title, items: _):
return title
}
}
init(original: MySectionModel, items: [Item]) {
switch original {
case let .a(title: title, items: _):
self = .a(title: title, items: items)
case let .b(title: title, items: _):
self = .b(title: title, items: items)
case let .c(title: title, items: _):
self = .c(title: title, items: items)
}
}
}