@@ -24,6 +24,9 @@ public class TableViewDataSource: NSObject {
24
24
25
25
/// Whether to show section titles
26
26
public var showSectionFooters : Bool ?
27
+
28
+ /// Whether cells should be configured inside a UIView.performWithoutAnimation closure
29
+ public var configureWithoutAnimations : Bool = true
27
30
28
31
/// Optional closure which is called after a cell is dequeued, but before it's being configured (e.g. to "reset" a cell)
29
32
public var prepareCell : ( ( UITableViewCell , indexPath: NSIndexPath ) -> Void ) ?
@@ -79,17 +82,31 @@ extension TableViewDataSource: UITableViewDataSource {
79
82
80
83
public func tableView( tableView: UITableView , cellForRowAtIndexPath indexPath: NSIndexPath ) -> UITableViewCell {
81
84
let row = dataSource. rowAtIndexPath ( indexPath)
82
-
83
- if let configurator = configuratorForRowIdentifier ( row. identifier) {
84
- let cell = tableView. dequeueReusableCellWithIdentifier ( configurator. cellIdentifier, forIndexPath: indexPath)
85
- prepareCell ? ( cell, indexPath: indexPath)
86
- configurator. configureRow ( row, cell: cell, indexPath: indexPath)
87
- return cell
85
+
86
+ let configure : ( ) -> UITableViewCell = {
87
+ if let configurator = self . configuratorForRowIdentifier ( row. identifier) {
88
+ let cell = tableView. dequeueReusableCellWithIdentifier ( configurator. cellIdentifier, forIndexPath: indexPath)
89
+ self . prepareCell ? ( cell, indexPath: indexPath)
90
+ configurator. configureRow ( row, cell: cell, indexPath: indexPath)
91
+ return cell
92
+ } else {
93
+ let cell = tableView. dequeueReusableCellWithIdentifier ( row. identifier, forIndexPath: indexPath)
94
+ self . prepareCell ? ( cell, indexPath: indexPath)
95
+ return cell
96
+ }
97
+ }
98
+
99
+ var cell : UITableViewCell ? = nil
100
+
101
+ if configureWithoutAnimations {
102
+ UIView . performWithoutAnimation {
103
+ cell = configure ( )
104
+ }
88
105
} else {
89
- let cell = tableView. dequeueReusableCellWithIdentifier ( row. identifier, forIndexPath: indexPath)
90
- prepareCell ? ( cell, indexPath: indexPath)
91
- return cell
106
+ cell = configure ( )
92
107
}
108
+
109
+ return cell!
93
110
}
94
111
95
112
public func tableView( tableView: UITableView , titleForHeaderInSection section: Int ) -> String ? {
0 commit comments