Created
March 8, 2015 17:08
-
-
Save ryanfitz/672be998a1c25887ed2a to your computer and use it in GitHub Desktop.
example function for reloading sections of ASTableViews
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func dataSource(dataSource: ASTableViewDataSource, removedSections: NSIndexSet?, insertedSections: NSIndexSet?, movedSections: [MovedIndex]?) { | |
dispatch_async(dispatch_get_main_queue()) { | |
self.tableView.ins_endPullToRefresh() | |
} | |
tableView.beginUpdates() | |
var del = NSMutableIndexSet() | |
var add = NSMutableIndexSet() | |
if let remove = removedSections { | |
del.addIndexes(remove) | |
} | |
if let inserts = insertedSections { | |
add.addIndexes(inserts) | |
} | |
if del.count == 0 && add.count == 0 { | |
if let moves = movedSections { | |
for move in moves.reverse() { | |
del.addIndex(move.oldIndex) | |
add.addIndex(move.newIndex) | |
} | |
} | |
} | |
if del.count > 0 { | |
tableView.deleteSections(del, withRowAnimation: .None) | |
} | |
if add.count > 0 { | |
tableView.insertSections(add, withRowAnimation: .None) | |
} | |
tableView.endUpdates() | |
if let context = self.batchContext { | |
context.completeBatchFetching(true) | |
self.batchContext = nil | |
} | |
delegate?.ViewControllerDidReloadLoadData?(self) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment