Reload tableview section without scroll or animation

后端 未结 8 873
轻奢々
轻奢々 2020-12-08 07:03

I am reloading a tableView section using this code -

self.tableView.beginUpdates()
self.tableView.reloadSections(NSIndexSet(index: 1), withRowAnimation: UITa         


        
相关标签:
8条回答
  • 2020-12-08 07:48

    Swift 4:

    Actually, the best way to prevent crazy animation during scrolling or expand/collapse cells is:

    UIView.performWithoutAnimation {
           self.tableView.reloadRows(at: [indexPath], with: .none)
    }
    
    0 讨论(0)
  • 2020-12-08 07:52

    Objective-C:

    [UIView setAnimationsEnabled:NO];
       [[self tableView]beginUpdates];
       [self.tableView reloadSections:[[NSIndexSet alloc] initWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
       [[self tableView]endUpdates];
    

    But I think the following code is more useful and better.

    [UIView performWithoutAnimation:^{     
                    [[self tableView]beginUpdates];
                    [self.tableView reloadSections:[[NSIndexSet alloc] initWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
                    [[self tableView]endUpdates];
                }];
    
    0 讨论(0)
提交回复
热议问题