-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewController.swift
42 lines (31 loc) · 1.14 KB
/
ViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import UIKit
import RxSwift
import RxCocoa
import RxDataSources
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
typealias Section = AnimatableSectionModel<String, String>
private let pollingSampler = Driver<Int>.interval(1)
private var pollingDisposable: Disposable?
private let dataSource = RxTableViewSectionedAnimatedDataSource<Section>()
override func viewDidLoad() {
super.viewDidLoad()
dataSource.configureCell = { _, tableView, indexPath, item in
let cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath)
cell.textLabel?.text = item.value
return cell
}
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
pollingDisposable = pollingSampler
.flatMapLatest { _ in Driver.just(["a", "b", "c"]) }
.doOnNext { _ in print("=> Tick.") }
.map { [Section(model: "", items: $0)] }
.drive(tableView.rx_itemsAnimatedWithDataSource(dataSource))
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
pollingDisposable?.dispose()
}
}