i want know end of reloadTableView Then I want to scroll down to the bottom of the table view.
Before I used RxSwift
Just after reloadData
It was possible using setContentOffSet
or ScrollToRow
.
I tried it with the code I found.
never called endUpdates
.
var replyList : BehaviorRelay<[Reply]>!
func bind(){
replyViewModel.replyList
.asDriver()
.drive(replyTableView.rx.items){ [weak self] (tableView,row,item) in
return self?.makeReplyCell(tableView: tableView, replyInfo: item) ?? UITableViewCell()
}
.disposed(by: disposeBag)
replyTableView.endUpdatesEvent
.asObservable()
.subscribe({ _ in
print("Scroll To Bottom")
})
.disposed(by: disposeBag)
}
import Foundation
import RxCocoa
import RxSwift
extension UITableView {
/// Reactive wrapper for `UITableView.insertRows(at:with:)`
var insertRowsEvent: ControlEvent<[IndexPath]> {
let source = rx.methodInvoked(#selector(UITableView.insertRows(at:with:)))
.map { a in
return a[0] as! [IndexPath]
}
return ControlEvent(events: source)
}
/// Reactive wrapper for `UITableView.endUpdates()`
var endUpdatesEvent: ControlEvent<Bool> {
let source = rx.methodInvoked(#selector(UITableView.endUpdates))
.map { _ in
return true
}
return ControlEvent(events: source)
}
/// Reactive wrapper for when the `UITableView` inserted rows and ended its updates.
var insertedItems: ControlEvent<[IndexPath]> {
let insertEnded = Observable.combineLatest(
insertRowsEvent.asObservable(),
endUpdatesEvent.asObservable(),
resultSelector: { (insertedRows: $0, endUpdates: $1) }
)
let source = insertEnded.map { $0.insertedRows }
return ControlEvent(events: source)
}
}