Skip to content

Commit 9cca67c

Browse files
committed
Handle potential table/collection view binding issue
1 parent 4004ade commit 9cca67c

4 files changed

Lines changed: 20 additions & 14 deletions

File tree

ReactiveUIKit.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Pod::Spec.new do |s|
22
s.name = "ReactiveUIKit"
3-
s.version = "1.0.6"
3+
s.version = "1.0.8"
44
s.summary = "Reactive extensions for UIKit framework."
55
s.homepage = "https://github.com/ReactiveKit/ReactiveUIKit"
66
s.license = 'MIT'
77
s.author = { "Srdan Rasic" => "srdan.rasic@gmail.com" }
8-
s.source = { :git => "https://github.com/ReactiveKit/ReactiveUIKit.git", :tag => "v1.0.6" }
8+
s.source = { :git => "https://github.com/ReactiveKit/ReactiveUIKit.git", :tag => "v1.0.8" }
99

1010
s.ios.deployment_target = '8.0'
1111
s.tvos.deployment_target = '9.0'

ReactiveUIKit/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0.6</string>
18+
<string>1.0.8</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

ReactiveUIKit/UICollectionView.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ extension ObservableCollectionType where Collection.Index == Int {
5454

5555
public class RKCollectionViewDataSource<C: ObservableCollectionType where C.Collection.Index == Int>: NSObject, UICollectionViewDataSource {
5656

57-
private let collection: C
57+
private let observableCollection: C
58+
private var sourceCollection: C.Collection
5859
private weak var collectionView: UICollectionView!
5960
private let createCell: (NSIndexPath, C.Collection, UICollectionView) -> UICollectionViewCell
6061
private weak var proxyDataSource: RKCollectionViewProxyDataSource?
@@ -64,15 +65,17 @@ public class RKCollectionViewDataSource<C: ObservableCollectionType where C.Coll
6465
self.collectionView = collectionView
6566
self.createCell = createCell
6667
self.proxyDataSource = proxyDataSource
67-
self.collection = collection
68+
self.observableCollection = collection
69+
self.sourceCollection = collection.collection
6870
self.animated = animated
6971
super.init()
7072

7173
collectionView.dataSource = self
7274
collectionView.reloadData()
7375

74-
collection.observe(on: ImmediateOnMainExecutionContext) { [weak self] event in
76+
observableCollection.observe(on: ImmediateOnMainExecutionContext) { [weak self] event in
7577
if let uSelf = self {
78+
uSelf.sourceCollection = event.collection
7679
if animated {
7780
uSelf.collectionView.performBatchUpdates({
7881
RKCollectionViewDataSource.applyRowUnitChangeSet(event, collectionView: uSelf.collectionView, sectionIndex: 0, dataSource: uSelf.proxyDataSource)
@@ -109,11 +112,11 @@ public class RKCollectionViewDataSource<C: ObservableCollectionType where C.Coll
109112
}
110113

111114
@objc public func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
112-
return collection.collection.count
115+
return sourceCollection.count
113116
}
114117

115118
@objc public func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
116-
return createCell(indexPath, collection.collection, collectionView)
119+
return createCell(indexPath, sourceCollection, collectionView)
117120
}
118121

119122
@objc public func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {

ReactiveUIKit/UITableView.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ extension ObservableCollectionType where Collection.Index == Int {
6565

6666
public class RKTableViewDataSource<C: ObservableCollectionType where C.Collection.Index == Int>: NSObject, UITableViewDataSource {
6767

68-
private let collection: C
68+
private let observableCollection: C
69+
private var sourceCollection: C.Collection
6970
private weak var tableView: UITableView!
7071
private let createCell: (NSIndexPath, C.Collection, UITableView) -> UITableViewCell
7172
private weak var proxyDataSource: RKTableViewProxyDataSource?
@@ -75,15 +76,17 @@ public class RKTableViewDataSource<C: ObservableCollectionType where C.Collectio
7576
self.tableView = tableView
7677
self.createCell = createCell
7778
self.proxyDataSource = proxyDataSource
78-
self.collection = collection
79+
self.observableCollection = collection
80+
self.sourceCollection = collection.collection
7981
self.animated = animated
8082
super.init()
81-
83+
8284
tableView.dataSource = self
8385
tableView.reloadData()
8486

85-
collection.observe(on: ImmediateOnMainExecutionContext) { [weak self] event in
87+
observableCollection.observe(on: ImmediateOnMainExecutionContext) { [weak self] event in
8688
if let uSelf = self {
89+
uSelf.sourceCollection = event.collection
8790
if animated {
8891
uSelf.tableView.beginUpdates()
8992
RKTableViewDataSource.applyRowUnitChangeSet(event, tableView: uSelf.tableView, sectionIndex: 0, dataSource: uSelf.proxyDataSource)
@@ -120,11 +123,11 @@ public class RKTableViewDataSource<C: ObservableCollectionType where C.Collectio
120123
}
121124

122125
@objc public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
123-
return collection.collection.count
126+
return sourceCollection.count
124127
}
125128

126129
@objc public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
127-
return createCell(indexPath, collection.collection, tableView)
130+
return createCell(indexPath, sourceCollection, tableView)
128131
}
129132

130133
@objc public func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {

0 commit comments

Comments
 (0)