Reload section without reloading section header

后端 未结 7 589
离开以前
离开以前 2020-12-08 08:03

I have a UITableView, where there is a UISegmentedControl in the header view. It should work exactly like in the App Store app: As the user scrolls

7条回答
  •  情话喂你
    2020-12-08 08:32

    An objective-c version of Intentss extension

    @interface UITableView (Extensions)
    
    - (void)reloadRowsInSection:(NSUInteger)sectionIndex withRowAnimation:(UITableViewRowAnimation)rowAnimation oldCount:(NSUInteger)oldCount newCount:(NSUInteger)newCount;
    
    @end
    
    
    @implementation UITableView (Extensions)
    
    - (void)reloadRowsInSection:(NSUInteger)sectionIndex withRowAnimation:(UITableViewRowAnimation)rowAnimation oldCount:(NSUInteger)oldCount newCount:(NSUInteger)newCount {
    
        NSUInteger minCount = MIN(oldCount, newCount);
    
        NSMutableArray *insert = [NSMutableArray array];
        NSMutableArray *delete = [NSMutableArray array];
        NSMutableArray *reload = [NSMutableArray array];
    
        for (NSUInteger row = oldCount; row < newCount; row++) {
            [insert addObject:[NSIndexPath indexPathForRow:row inSection:sectionIndex]];
        }
    
        for (NSUInteger row = newCount; row < oldCount; row++) {
            [delete addObject:[NSIndexPath indexPathForRow:row inSection:sectionIndex]];
        }
    
        for (NSUInteger row = 0; row < minCount; row++) {
            [reload addObject:[NSIndexPath indexPathForRow:row inSection:sectionIndex]];
        }
    
        [self beginUpdates];
    
        [self insertRowsAtIndexPaths:insert withRowAnimation:rowAnimation];
        [self deleteRowsAtIndexPaths:delete withRowAnimation:rowAnimation];
        [self reloadRowsAtIndexPaths:reload withRowAnimation:rowAnimation];
    
        [self endUpdates];
    }
    
    @end
    

提交回复
热议问题