reload uitableview with new data caused flickering

后端 未结 9 1094
Happy的楠姐
Happy的楠姐 2020-12-16 11:55

I added an infinite scrolling feature and realized that whenever I reload the uitableview, the view flickers..I am not sure how to fix the flickering at this point. Please h

9条回答
  •  情话喂你
    2020-12-16 12:32

        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationNone];
    

    whenever you remove or add a table row in updates..the table view reloads and ask the datasource for the number of rows based on which cell is animated to position.

    you are removing row from table but not from datasource..so rows are deleted but your datasource still points out that no row is deleted..20 objects are still there. your data source will be something like

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return MyDataModel.count; // 
    }
    

    so you need to remove or add new data in datasource also..something like this

       NSIndexPath *index = [NSIndexPath indexPathForRow:i inSection:0];
       [MyDataModel removeObjectAtIndex:index.row];
       [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationNone];
    

提交回复
热议问题