2010-08-14 21 views
6

Ok Ragazzi, ecco la situazione che ho.Ricarica solo un UITableViewCell su un UITableview

Utilizzo un UITableViewController con dati di base. Il tavolo ha circa 200 celle, che fondamentalmente funzionano come una lista di controllo. Quando tocchi una cella, quella cella ha una casella di controllo che viene impostata su UITableViewCell.imageView (UIImageView assegnato a sinistra dell'etichetta).

Ogni volta che uso uno dei due modi seguenti per aggiornare la tabella, ci vogliono circa 1 - 2 secondi per l'aggiornamento ... e da quello che posso dire, sembra che si stia ricaricando ogni cella. Come posso forzare ad aggiornare solo la cella che è stata appena TAPpata?

[self.tableView reloadData]; o

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { 
    [self.tableView beginUpdates]; 
} 

- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo 
      atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type { 

    switch(type) { 
     case NSFetchedResultsChangeInsert: 
      [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] 
          withRowAnimation:NO]; 
      break; 

     case NSFetchedResultsChangeDelete: 
      [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] 
          withRowAnimation:NO]; 
      break; 
    } 
} 

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject 
     atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type 
     newIndexPath:(NSIndexPath *)newIndexPath { 

    UITableView *tableView = self.tableView; 

    switch(type) { 

     case NSFetchedResultsChangeInsert: 
      [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] 
          withRowAnimation:NO]; 
      break; 

     case NSFetchedResultsChangeDelete: 
      [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
          withRowAnimation:NO]; 
      break; 

     case NSFetchedResultsChangeUpdate: 
      [self configureCell:[tableView cellForRowAtIndexPath:indexPath] 
        atIndexPath:indexPath]; 
      break; 

     case NSFetchedResultsChangeMove: 
      [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
          withRowAnimation:NO]; 
      [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] 
          withRowAnimation:NO]; 
      break; 
    } 
} 

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { 
    [self.tableView endUpdates]; 
} 
+0

Ho w hai aggiornato i dati nel modello? Sembra che tutte le celle vengano aggiornate. – geon

+0

il secondo parametro di '-insertSections: withRowAnimation:', '-deleteSections: withRowAnimation:', '-insertRowsAtIndexPaths: withRowAnimation:', e '-deleteRowsAtIndexPaths: withRowAnimation:' non sono 'BOOL'; sono un tipo 'UITableViewRowAnimation' – user102008

risposta

0

Se stai solo aggiornando TextLabel della cellula testo- questo codice è sufficiente

UITableViewCell *cell = [_myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]]; 

    cell.textLabel.text = [NSString stringWithFormat:@"%i", (int)_targetMaxDistanceSlider.value]; 
Problemi correlati