I am writing an app that notifies user when its time to take his/her medicine. The label at the top of the page shows a date and the tableView
gets populated with m
Here is the method, you can pass section details in different ways
[self.tableView reloadSections:[[NSIndexSet alloc] initWithIndex:1] withRowAnimation:NO];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
Reloading particular sections improves performance for the table view as well some time it also avoid some issues like floating/moving custom headers-footers in your view. SO try to use reloadSection than relaodData whenever possible
There are few functions supported in UITableView for reloading data. See section Reloading the Table View of doc.
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.
Use this method to reload your section
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
Swift 3
NSIndexSet is nothing special
tableView.reloadSections([1, 2, 3], with: .none)
It's just an array. Crazy.
You can use this also--
indexPath.section
- `UITableView section which you want to reload .
NSIndexSet *section = [NSIndexSet indexSetWithIndex:indexPath.section];
[self.tableView reloadSections:section withRowAnimation:UITableViewRowAnimationNone];
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)