Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView reload section

I want to reload only one section not the full table. Is there any method in UITableView.

[tableView reloadData] is used to load full table.
I want to know how to load only one section, as I have large number of rows in the table.

like image 573
Anil Kothari Avatar asked Nov 29 '11 06:11

Anil Kothari


People also ask

How do you refresh a table view?

If you want to reload your table view while also saving and restoring any selections, you should take a copy of the indexPathsForSelectedRows property before the reload, then re-apply those selections after calling reloadData() . With that in place, you can now call yourTableView.

What does Tableview reload data do?

reloadData()Reloads the rows and sections of the table view.


2 Answers

The reloadSections method bugs me -- as I have to construct a few objects. This is great if you need the flexibility, but sometimes I also just want the simplicity too. It goes like this:

NSRange range = NSMakeRange(0, 1); NSIndexSet *section = [NSIndexSet indexSetWithIndexesInRange:range];                                      [self.tableView reloadSections:section withRowAnimation:UITableViewRowAnimationNone]; 

This will reload the first section. I prefer to have a category on UITableView and just call this method:

[self.tableView reloadSectionDU:0 withRowAnimation:UITableViewRowAnimationNone]; 

My category method looks like this:

@implementation UITableView (DUExtensions)  - (void) reloadSectionDU:(NSInteger)section withRowAnimation:(UITableViewRowAnimation)rowAnimation {     NSRange range = NSMakeRange(section, 1);     NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];                                          [self reloadSections:sectionToReload withRowAnimation:rowAnimation]; } 
like image 146
bandejapaisa Avatar answered Sep 24 '22 10:09

bandejapaisa


Yes, there is:

- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation 
like image 34
sosborn Avatar answered Sep 23 '22 10:09

sosborn