UITableView reload section

前端 未结 11 2079
余生分开走
余生分开走 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:39

    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];
    }
    

提交回复
热议问题