Skip to content

Instantly share code, notes, and snippets.

@ryanfitz
Created March 8, 2015 17:08
Show Gist options
  • Save ryanfitz/672be998a1c25887ed2a to your computer and use it in GitHub Desktop.
Save ryanfitz/672be998a1c25887ed2a to your computer and use it in GitHub Desktop.
example function for reloading sections of ASTableViews
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