Chế độ xem bảng của tôi hiển thị danh sách người dùng. Tôi đang gặp sự cố khi làm mới chế độ xem bảng của mình sau khi thêm người dùng. Tôi đã thử kết hợp mã và sự kiện khác nhau và bây giờ ứng dụng đang gặp sự cố trong cuộc gọi endUpdates. Ứng dụng được mô hình hóa sau ứng dụng công thức, vì vậy người dùng nhấp vào nút thêm và sau đó cửa sổ phương thức xuất hiện yêu cầu tên người dùng. Sau đó, nó đi vào màn hình chỉnh sửa, và sau đó trở lại danh sách người dùng. Tại thời điểm đó, người dùng mới không hiển thị. Nhưng nếu tôi điều hướng trở lại màn hình chính, và sau đó quay lại màn hình người dùng, người dùng sẽ xuất hiện.Ứng dụng iPhone gặp lỗi trên [self.tableView endUpdates]
Dưới đây là một số mã của tôi:
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
sectionInsertCount = 0;
[self.tableView beginUpdates];
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[self.tableView endUpdates];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
switch(type) {
case NSFetchedResultsChangeInsert:
if (!((sectionIndex == 0) && ([self.tableView numberOfSections] == 1))) {
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
sectionInsertCount++;
}
break;
case NSFetchedResultsChangeDelete:
if (!((sectionIndex == 0) && ([self.tableView numberOfSections] == 1))) {
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
sectionInsertCount--;
}
break;
case NSFetchedResultsChangeMove:
break;
case NSFetchedResultsChangeUpdate:
break;
default:
break;
}
}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
switch(type) {
case NSFetchedResultsChangeInsert:
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate: {
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
case NSFetchedResultsChangeMove:
if (newIndexPath != nil) {
NSUInteger tableSectionCount = [self.tableView numberOfSections];
NSUInteger frcSectionCount = [[controller sections] count];
if (frcSectionCount != tableSectionCount + sectionInsertCount) {
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:[newIndexPath section]] withRowAnimation:UITableViewRowAnimationNone];
sectionInsertCount++;
}
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPaths: [NSArray arrayWithObject:newIndexPath]
withRowAnimation: UITableViewRowAnimationRight];
runEndUpdates = NO;
}
else {
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:[indexPath section]] withRowAnimation:UITableViewRowAnimationFade];
}
break;
default:
break;
}
}
Tôi gần như tại một điểm phá vỡ với điều này. CoreData là phần bực bội nhất trong phát triển ứng dụng. Tôi có nên chuyển sang SQL Lite không? Hoặc tôi vẫn sẽ có những vấn đề tương tự?
Cảm ơn!
Nhưng nếu bạn sử dụng fetchedResultsController (giống như tác giả đã làm) - nó rất khó để thực hiện một sai lầm ở đây :) Số phần: return [self.fetchedResultsController.sections count]; Số hàngInSection: trả về [self.fetchedResultsController.sections [section] numberOfObjects]; – Miroslav