2010-08-14 19 views
6

ठीक दोस्तों पर केवल एक UITableViewCell को फिर से लोड करना, यहां मेरी स्थिति है।UITableview

मैं कोर डेटा के साथ एक UITableViewController का उपयोग कर रहा हूँ। तालिका में लगभग 200 कोशिकाएं हैं, जो मूल रूप से चेकलिस्ट के रूप में कार्य करती हैं। जब आप किसी सेल को टैप करते हैं, तो उस सेल में एक चेकबॉक्स होता है जो UITableViewCell.imageView पर सेट टॉगल हो जाता है (UIImageView लेबल के बाईं ओर असाइन किया गया है)।

जब भी मैं तालिका को अद्यतन करने के लिए नीचे दिए गए दो तरीकों में से किसी एक का उपयोग करता हूं, तो अपडेट के लिए लगभग 1 - 2 सेकंड लगते हैं ... और जो मैं कह सकता हूं, उससे प्रत्येक सेल को फिर से लोड करना प्रतीत होता है। मैं केवल उस सेल को कैसे मजबूर कर सकता हूं जिसे अद्यतन करने के लिए अभी टैप किया गया था?

[self.tableView reloadData]; या

- (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

हो क्या आप मॉडल में डेटा अपडेट करते हैं? ऐसा लगता है जैसे सभी कोशिकाओं को अद्यतन किया जाता है। – geon

+0

'-insertSections का दूसरा पैरामीटर: withRowAnimation:', '-deleteSections: withRowAnimation:', '-insertRowsAtIndexPaths: withRowAnimation:', और '-deleteRowsAtIndexPaths: withRowAnimation:' 'BOOL' नहीं हैं; वे एक 'UITableViewRowAnimation' प्रकार – user102008

उत्तर

37

आप इस की जरूरत है:

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation 

http://developer.apple.com/iphone/library/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006943-CH3-SW40

+0

हैं, मुझे वास्तव में प्रश्न पोस्ट करने के कुछ मिनट बाद मिले और यह पूरी तरह से काम किया। धन्यवाद! – Travis

+0

बहुत बहुत धन्यवाद! –

0

तुम सिर्फ इस कोड को पाठ सेल की पाठलेबल अपडेट कर रहे हैं पर्याप्त है

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

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