Reload sections in UITableView
Swift 3
NSIndexSet is nothing special
tableView.reloadSections([1, 2, 3], with: .none)
It's just an array. Crazy.
There are few functions supported in UITableView for reloading data. See section Reloading the Table View of doc.
- reloadData
- reloadRowsAtIndexPaths:withRowAnimation:
- reloadSections:withRowAnimation:
- reloadSectionIndexTitles
Also, see this similar thread, a part from it:
NSRange range = NSMakeRange(0, 1);
NSIndexSet *section = [NSIndexSet indexSetWithIndexesInRange:range];
[self.tableView reloadSections:section withRowAnimation:UITableViewRowAnimationNone];
Also, it is not necessary to reload specific sections, you can just adjust your dataset and call [tableView reloadData]
, it will load the visible cells only. A part from doc:
Call this method to reload all the data that is used to construct the table, including cells, section headers and footers, index arrays, and so on. For efficiency, the table view redisplays only those rows that are visible. It adjusts offsets if the table shrinks as a result of the reload.
Update for quick usage in Swift (as of 2.2)
// index 0 being the section number 1 that you will reload
tableView.reloadSections(NSIndexSet(index: 0), withRowAnimation: .None)