RxSwift,删除带有动画的单元格
RxSwift, remove cell with animation
我在单元格中有一个自定义按钮,用于从可观察列表中删除项目。
self.searchListViewModel.genericList.value.remove(at: index)
所有逻辑都运行良好,但我需要一个动画来删除 cell.Something 像这样
self.tableView.deleteRows(at: [IndexPath(row: index, section: 0)],
with: .fade)
但现在,如果我尝试同时使用两者,应用程序会崩溃。
抱歉耽搁了。这是 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 { [=11=] }
}
}
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)
}
}
}
我在单元格中有一个自定义按钮,用于从可观察列表中删除项目。
self.searchListViewModel.genericList.value.remove(at: index)
所有逻辑都运行良好,但我需要一个动画来删除 cell.Something 像这样
self.tableView.deleteRows(at: [IndexPath(row: index, section: 0)],
with: .fade)
但现在,如果我尝试同时使用两者,应用程序会崩溃。
抱歉耽搁了。这是 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 { [=11=] }
}
}
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)
}
}
}