Vishal Singh Vishal Singh - 1 year ago 87
Objective-C Question

how to reload tableview's particular section

I have 56 sections in my tableview, and I am storing the section number which is currently selected in an integer variable named "activeTimeSlot". How to use the below method to reload a section which is currently selected. I am doing it like

[self.tblView reloadSections:[NSIndexSet indexSetWithIndex:activeTimeSlot] withRowAnimation:UITableViewRowAnimationAutomatic];

but I have observed that doing this way is calling the below datasource method of tableview for all the sections, i.e its reloading all the section.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

I am not sure how to use NSIndexSet and how to use NSIndexSet to reload more than 1 sections.

Answer Source

As I saw from your comments, you are checking the call of the method

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

to figure out that it's reloading every section. But that method is called for all the sections for internal reasons probably. If you try to log which rows are actually realoaded, you'll see that everything is fine. put a

NSLog(@"Section %d", indexPath.section);


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

and see that just rows from the selected section are reloaded.

PS: forgot to say: your solution was already correct.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download