Ok Các bạn, đây là tình huống tôi có.Chỉ tải lại một UITableViewCell trên UITableview
Tôi đang sử dụng UITableViewController với Dữ liệu chính. Bảng này có khoảng 200 ô, về cơ bản có chức năng như một danh sách kiểm tra. Khi bạn nhấn vào một ô, ô đó có một hộp kiểm được chuyển thành UITableViewCell.imageView (UIImageView được gán ở bên trái nhãn). Bất cứ lúc nào tôi sử dụng một trong hai cách dưới đây để cập nhật bảng, mất khoảng 1 - 2 giây để cập nhật ... và từ những gì tôi có thể nói, có vẻ như nó đang tải lại mọi ô. Làm thế nào tôi có thể buộc chỉ các tế bào đã được khai thác để được cập nhật?
[self.tableView reloadData];
hoặc
- (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];
}
Ho Bạn có cập nhật dữ liệu trong mô hình không? Có vẻ như tất cả các ô đều được cập nhật. – geon
tham số thứ hai của '-insertSections: withRowAnimation:', '-deleteSections: withRowAnimation:', '-insertRowsAtIndexPaths: withRowAnimation:', và '-deleteRowsAtIndexPaths: withRowAnimation:' không phải là 'BOOL'; họ là một loại 'UITableViewRowAnimation' – user102008