Skip to content

Commit eddf011

Browse files
committed
perform configuration inside a performWithoutAnimation closure by default
1 parent d4fbbdd commit eddf011

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

Diff for: DataSource/TableViewDataSource.swift

+26-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public class TableViewDataSource: NSObject {
2424

2525
/// Whether to show section titles
2626
public var showSectionFooters: Bool?
27+
28+
/// Whether cells should be configured inside a UIView.performWithoutAnimation closure
29+
public var configureWithoutAnimations: Bool = true
2730

2831
/// Optional closure which is called after a cell is dequeued, but before it's being configured (e.g. to "reset" a cell)
2932
public var prepareCell: ((UITableViewCell, indexPath: NSIndexPath) -> Void)?
@@ -79,17 +82,31 @@ extension TableViewDataSource: UITableViewDataSource {
7982

8083
public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
8184
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+
}
88105
} else {
89-
let cell = tableView.dequeueReusableCellWithIdentifier(row.identifier, forIndexPath: indexPath)
90-
prepareCell?(cell, indexPath: indexPath)
91-
return cell
106+
cell = configure()
92107
}
108+
109+
return cell!
93110
}
94111

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

Diff for: Example.xcodeproj/project.pbxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@
160160
395D14A51B90612D00658680 /* DataSource */ = {
161161
isa = PBXGroup;
162162
children = (
163-
39D82E581C04AC2C002A7B1B /* Extensions */,
164163
395D14A61B90612D00658680 /* DataSource.h */,
165164
39D82E491C049ABE002A7B1B /* DataSource.swift */,
165+
39D82E581C04AC2C002A7B1B /* Extensions */,
166166
395D14A81B90612D00658680 /* Info.plist */,
167167
3949A38E1C0706A200715B7F /* TableViewCellConfigurator.swift */,
168168
39D82E4D1C049C34002A7B1B /* TableViewDataSource.swift */,

Diff for: Example/Info.plist

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.1</string>
18+
<string>1.2</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>5</string>
22+
<string>6</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true/>
2525
<key>UILaunchStoryboardName</key>

0 commit comments

Comments
 (0)