iOS - UITableView refresh table properly?

前端 未结 3 1078
一生所求
一生所求 2020-12-24 12:57

I have lots of data and lots of rows in my tableView. when data changes I want to update my visible cells on the screen, I really don\'t want to use reloadData because it\'s

相关标签:
3条回答
  • 2020-12-24 13:17

    You can:

    [tableView reloadRowsAtIndexPaths:[tableView indexPathsForVisibleRows] 
                     withRowAnimation:UITableViewRowAnimationNone];
    
    0 讨论(0)
  • 2020-12-24 13:30

    Try calling 'deleteRowsAtIndexPaths', a method of UITableView, right after you delete the model from your data source. For example, if you are deleting a row in editing mode, you could write something like the code below. Note that the first line in the 'if' statement removes the object from the data source, and the second line cleans up the table:

    -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
        if ( editingStyle == UITableViewCellEditingStyleDelete ) {
    
             [[[[[ItemsStore sharedStore] parameterArray] objectAtIndex:indexPath.section]  objectForKey:@"data"] removeObjectAtIndex:indexPath.row];
    
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    
        }
    }
    
    0 讨论(0)
  • 2020-12-24 13:33

    For Swift 3:

    tableView.reloadRows(at: tableView.indexPathsForVisibleRows!, with: .none)
    
    0 讨论(0)
提交回复
热议问题