UITableView reload section

前端 未结 11 2060
余生分开走
余生分开走 2020-12-05 01:46

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

11条回答
  •  春和景丽
    2020-12-05 02:19

    Based on the accepted answer here, I made a function that will reload all sections in the table using an animation. This could probably be optimized by reloading only visible sections.

    [self.tableView reloadData];
    NSRange range = NSMakeRange(0, [self numberOfSectionsInTableView:self.tableView]);
    NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:range];
    [self.tableView reloadSections:sections withRowAnimation:UITableViewRowAnimationFade];
    

    In my case, I had to force a reloadData before the section animation, because the underlying data for the table had changed. It animates properly however.

提交回复
热议问题