CellForRowAtIndexPath not called after reloadRowsAtIndexPaths

According to Apple Doc ,

Reloading the row causes the table view to query the data source for a new cell for that row.

I am combining a UITableView with NSFetchedResultsController:

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { if (self.tableView.isEditing) { [self.tableView setEditing:NO animated:YES]; } [self.tableView beginUpdates]; } - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { [self.tableView endUpdates]; [self updateTabItemBadge]; [self.noDataView setHidden:![self isNoData]]; WXINFO(@"controllerDidChangeContent"); } 

Between the two functions above, I reload the target cell:

enter image description here

  case NSFetchedResultsChangeUpdate: { if (indexPath) { [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; } 

enter image description here

I set a breakpoint in Line1563 to verify that the call to reloadRowsAtIndexPaths was called, but after that - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath not called.

So my cell cannot be updated.

Can anyone tell me why? Thanks.

+6
source share
4 answers

Could you check by reloading the table view using [tableView reloadData]?

If you want to update only one row without reloading the table, check the type 'indexPath'. It must be NSIndexPath.

0
source

Wrap it in:

 [tableView beginUpdates]; [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; [tableView endUpdates]; 
0
source

The only reliable way I found for this is to use animations other than it. If any other animation is specified, the reboot occurs correctly.

0
source

This is the work I did, but she did the job.

  func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == UITableViewCellEditingStyle.delete { if itemDetailDict.count - 1 <= 0 { self.mainTable.beginUpdates() let cellOne = self.mainTable.cellForRow(at: indexPath) cellOne?.textLabel?.text = "There are no items." self.mainTable.reloadRows(at: [indexPath], with: .automatic) self.mainTable.endUpdates() } else { self.mainTable.beginUpdates() let removeKey = Array(itemDetailDict.keys)[indexPath.row] itemDetailDict.removeValue(forKey: removeKey) mainTable.deleteRows(at: [indexPath], with: .automatic) self.mainTable.endUpdates() } } } 

Essentially in the delete row function, I wanted the user to be able to delete the row, but when there was only one row left, I wanted to show the default message in the table cell.

To do this, I updated the data source, and when there was no more data in the dictionary, I updated the cell to display the text, reloaded the cell, and then called endUpdating in my table view.

Hope this helps.

0
source

Source: https://habr.com/ru/post/948599/


All Articles