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.
If you want to update multiple section then you can do this way.
NSMutableIndexSet *indetsetToUpdate = [[NSMutableIndexSet alloc]init];
[indetsetToUpdate addIndex:previousSection]; // [indetsetToUpdate addIndex:<#(NSUInteger)#>]
// You can add multiple indexes(sections) here.
[detailTableView reloadSections:indetsetToUpdate withRowAnimation:UITableViewRowAnimationFade];
This is used for updating multiple sections and it's working fine for me.
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);
in
- (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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With