Insert UITableView row without ANY animation

前端 未结 5 2092
感情败类
感情败类 2021-02-07 02:05
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:row inSection:0]] 
                      withRowAnimation:UITableViewRowAnimationNone];


        
相关标签:
5条回答
  • 2021-02-07 02:46

    If you update the UITableView's dataSource and call [tableView reloadData] instead of manually inserting the row, the table will refresh without any animation.

    0 讨论(0)
  • 2021-02-07 02:50

    This works for me:

    [UIView setAnimationsEnabled:NO];
    [self.tableView beginUpdates];
    
    [self.tableView insertRowsAtIndexPaths:indexPath
                          withRowAnimation:UITableViewRowAnimationNone];
    
    [self.tableView endUpdates];
    [UIView setAnimationsEnabled:YES];
    

    Hope this helps.

    0 讨论(0)
  • 2021-02-07 02:51

    This also works

    [UIView performWithoutAnimation:^{
        [self.tableView insertRowsAtIndexPaths:indexPaths:withRowAnimation:UITableViewRowAnimationNone];
    });
    
    0 讨论(0)
  • 2021-02-07 02:59

    Swift example (from my chat)

    UIView.performWithoutAnimation {
            messagesTable.insertRows(at: [IndexPath(row: messages.count - 1, section: 0)], with: .none)
        }
    
    0 讨论(0)
  • 2021-02-07 03:09

    Unfortunately, I ran into this same issue and there was no way for me to remove the animation.

    Must be a bug with the UITableViewRowAnimationNone animation type since iOS (of any version) does not seem to respect it.

    0 讨论(0)
提交回复
热议问题