Skip to content

Commit aec86f0

Browse files
committed
Adds programatic responding to canEditRowAtIndexPath.
1 parent ec6e626 commit aec86f0

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

Example/Example4_DifferentSectionAndItemTypes.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class MultipleSectionModelViewController: UIViewController {
3131

3232
let dataSource = RxTableViewSectionedReloadDataSource<MultipleSectionModel>()
3333

34-
Observable.just(sections)
34+
skinTableViewDataSource(dataSource)
35+
36+
Observable.just(sections)
3537
.bindTo(tableView.rx_itemsWithDataSource(dataSource))
3638
.addDisposableTo(disposeBag)
37-
38-
skinTableViewDataSource(dataSource)
3939
}
4040

4141
func skinTableViewDataSource(dataSource: RxTableViewSectionedReloadDataSource<MultipleSectionModel>) {
@@ -60,14 +60,17 @@ class MultipleSectionModelViewController: UIViewController {
6060
return cell
6161
}
6262
}
63-
63+
64+
dataSource.canEditRowAtIndexPath = { _ in
65+
return false
66+
}
67+
6468
dataSource.titleForHeaderInSection = { dataSource, index in
6569
let section = dataSource.sectionAtIndex(index)
6670

6771
return section.title
6872
}
6973
}
70-
7174
}
7275

7376
enum MultipleSectionModel {

Sources/DataSources/TableViewSectionedDataSource.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ public class _TableViewSectionedDataSource
5656
public func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? {
5757
return _rx_tableView(tableView, titleForFooterInSection: section)
5858
}
59-
59+
60+
public var canEditRowAtIndexPathImplemented: Bool {
61+
return false
62+
}
63+
6064
func _rx_tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
6165
return true
6266
}
@@ -95,6 +99,14 @@ public class _TableViewSectionedDataSource
9599
public func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
96100
_rx_tableView(tableView, moveRowAtIndexPath: sourceIndexPath, toIndexPath: destinationIndexPath)
97101
}
102+
103+
override public func respondsToSelector(aSelector: Selector) -> Bool {
104+
if aSelector == #selector(UITableViewDataSource.tableView(_:canEditRowAtIndexPath:)) {
105+
return self.canEditRowAtIndexPathImplemented
106+
}
107+
108+
return super.respondsToSelector(aSelector)
109+
}
98110
}
99111

100112
public class RxTableViewSectionedDataSource<S: SectionModelType>
@@ -148,6 +160,10 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
148160
public var titleForFooterInSection: ((RxTableViewSectionedDataSource<S>, section: Int) -> String?)?
149161

150162
public var canEditRowAtIndexPath: ((RxTableViewSectionedDataSource<S>, indexPath: NSIndexPath) -> Bool)?
163+
override public var canEditRowAtIndexPathImplemented: Bool {
164+
let result = canEditRowAtIndexPath != nil
165+
return result
166+
}
151167
public var canMoveRowAtIndexPath: ((RxTableViewSectionedDataSource<S>, indexPath: NSIndexPath) -> Bool)?
152168

153169
public var sectionIndexTitles: ((RxTableViewSectionedDataSource<S>) -> [String]?)?

0 commit comments

Comments
 (0)