मैं संग्रह दृश्य कंट्रोलर में NSFetchedResultsControllerRelegate का उपयोग करना चाहता हूं। इसलिए मैंने संग्रह दृश्य के लिए TableViewController के लिए विधि को अभी बदल दिया है।संग्रह दृश्य के लिए NSFetchedResultsContollerDelegate
(void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
switch(type) {
case NSFetchedResultsChangeInsert:
[self.collectionView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]];
break;
case NSFetchedResultsChangeDelete:
[self.collectionView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] ];
break;
}
}
(void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {
UICollectionView *collectionView = self.collectionView;
switch(type) {
case NSFetchedResultsChangeInsert:
[collectionView insertItemsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]];
break;
case NSFetchedResultsChangeDelete:
[collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
break;
case NSFetchedResultsChangeUpdate:
[collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
break;
case NSFetchedResultsChangeMove:
[collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
[collectionView insertItemsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]];
break;
}
}
(void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[self.collectionView reloadData];
}
लेकिन मैं एक CollectionView
के लिए (TableVie
w के लिए endUpdates
) WillChangeContent
(beginUpdates
TableView
के लिए) और DidChangeContent
को संभालने के लिए कैसे पता नहीं है।
सबकुछ ठीक काम करता है सिवाय इसके कि जब मैं एक आइटम को एक सेक्शन में दूसरे अनुभाग में ले जाता हूं। तब मुझे निम्न त्रुटि मिलती है।
यह आमतौर पर NSManagedObjectContextObjectsDidChangeNotification के पर्यवेक्षक के भीतर एक बग है। अमान्य अद्यतन: खंड 0 में आइटमों की अवैध संख्या ....
कोई विचार मैं इस समस्या को कैसे हल कर सकता हूं?
धन्यवाद, मार्टिन। मैंने पहले बिना काम के इस कोशिश की - कामकाज के लिए अद्यतन नहीं देखा। अब संग्रह में बग के कामकाज के साथ यह अंततः काम करता है। इस तथ्य के कारण कि मेरे पास हेडर और पाद लेख हैं, यह बहुत अच्छी मदद थी। मुझे आशा है कि फिर भी यह बग एक बार हल हो जाएगा। – aquarius68
@ Aquarius68: यह वास्तव में एक बग नहीं है। समस्या यह है कि एफआरसी प्रतिनिधि विधियों और संग्रह दृश्य अद्यतन विधियां वास्तव में एक साथ फिट नहीं होती हैं। फिक्स्डिंग का मतलब एपीआई में से किसी एक को बदलना या विस्तार करना है। - लेकिन मुझे खुशी है कि आप इसे काम कर रहे हैं। –
मुझे अब और त्रुटि संदेश नहीं मिलते हैं लेकिन यह अभी तक पूरी तरह से काम नहीं करता है; यानी यदि उपयोगकर्ता पहला तत्व जोड़ता है तो यह काम करता है, लेकिन यदि उपयोगकर्ता दूसरा तत्व जोड़ता है तो यह केवल तभी काम करता है जब मैं तालिका दृश्य पर वापस जाता हूं जिसमें संग्रह दृश्य की वस्तुओं से संबंधित वस्तुएं होती हैं। – aquarius68