मेरे पास एक UITableView है जो CoreData के साथ संग्रहीत वस्तुओं की एक सूची दिखाता है। मैं निम्नलिखित कोड का उपयोग कर ऑब्जेक्ट को हटा सकता हूं:कोरडाटा के साथ UITableView में पंक्ति हटाने को एनिमेटिंग असर विफलता
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSLog(@"Delete row");
[managedObjectContext deleteObject:[fetchedResultsController objectAtIndexPath:indexPath]];
// Save the context.
NSError *error;
if (![managedObjectContext save:&error]) {
/*do this gracefully one day */
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
[self refreshTables]; //where refreshTables just reloads the data the table is using and calls [self.tableView reloadData];
}
}
लेकिन इसमें कोई एनीमेशन या सौंदर्य नहीं है।
जब मैं
[self refreshTables];
जगह
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
साथ द्वारा चेतन करने की कोशिश मैं निम्नलिखित त्रुटि मिलती है:
Assertion failure in -[UITableView _endCellAnimationsWithContext:], >/SourceCache/UIKit_Sim/UIKit-1261.5/UITableView.m:920 2010-10-30 16:46:35.717 MyApp[38226:207] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).'
मैं में deleteRowsAtIndexPaths कोड होने की कोशिश की है कोई lu के साथ commit एडिटिंग स्टाइल कोड में विभिन्न स्थानों सीके (उदाहरण के लिए एमओसी से ऑब्जेक्ट को हटाने से पहले) लेकिन मुझे इस त्रुटि के आसपास नहीं लग रहा है।
मुझे पता है कि ऐप्पल के आईफोनकोरेडाटा रेसिपेस उदाहरण को संपादित/हटाना पंक्तियों को संभालने के लिए FetchedResultsController के लिए एक प्रतिनिधि सेट अप करके समस्या को संभालता है, लेकिन यदि संभव हो तो विकास में इस चरण में, मैं बस उन हटाए गए ऑब्जेक्ट्स को एनिमेट करने के लिए एक सरल समाधान चाहता हूं।
मैं अपने प्रबंधित ऑब्जेक्ट कॉन्टेक्स्ट से ऑब्जेक्ट को हटाने से पहले/बाद में पंक्ति को हटाने का एनीमेट कैसे कर सकता हूं?
संपादित करें: मैंने उसी त्रुटि के साथ एमओसी से आइटम को हटाने से पहले और बाद में DeleteRowsAtIndexPaths को हटाने का प्रयास किया है।
# 2 मेरी समस्या तय की। धन्यवाद! –