अद्यतन के साथ वर्गोंUITableView: को हटाने एनीमेशन
मैं नीचे एक जवाब के रूप इस समस्या का समाधान मेरी पोस्ट किया है। यह मेरे पहले संशोधन से एक अलग दृष्टिकोण लेता है।
मूल प्रश्न मैं पहले इतने पर एक प्रश्न पूछा है कि मैं अपने मुद्दों को हल कर सोचा:
How to deal with non-visible rows during row deletion. (UITableViews)
हालांकि, मैं अब इसी तरह की समस्याओं फिर से जब एक UITableView से वर्गों को हटाने की है। (जब मैंने तालिका में अनुभागों/पंक्तियों की संख्या को अलग किया तो वे पुन: जीवित हुए)।
मेरी पोस्ट की कतरनी लंबाई के कारण मैं आपको खोने से पहले, मुझे समस्या स्पष्ट रूप से बताएं, और आप जितना अधिक जवाब देने के लिए आवश्यक हो उतना पढ़ सकते हैं।
समस्या:
बैच एक UITableView, अनुप्रयोग क्रैश से पंक्तियों और वर्गों को हटाने, तो कभी कभी। यह तालिका की कॉन्फ़िगरेशन और पंक्तियों और खंडों के संयोजन पर निर्भर करता है जिन्हें मैं निकालना चुनता हूं। अब जल्दी से
Invalid update: invalid number of rows in section 5. The number of rows contained in an existing section after the update (2) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted).
, इससे पहले कि आप स्पष्ट जवाब लिखते हैं, मैं आपको विश्वास दिलाता मैं वास्तव में जोड़ लिया है और नष्ट कर दिया:
लॉग मैं दुर्घटनाग्रस्त हो गया है, क्योंकि यह कहता है कि मैं डेटा स्रोत और ठीक से तालिका अद्यतन नहीं किया है कहते हैं डेटा स्रोत से ठीक से पंक्तियां और खंड। स्पष्टीकरण लंबा है, लेकिन विधि के बाद, आप इसे नीचे पाएंगे।
उस के साथ तो, अगर आप अभी भी रुचि रखते हैं ...
विधि कि वर्गों और पंक्तियों को हटाने के हैंडल:
- (void)createFilteredTableGroups{
//index set to hold sections to remove for deletion animation
NSMutableIndexSet *sectionsToDelete = [NSMutableIndexSet indexSet];
[sectionsToDelete removeIndex:0];
//array to track cells for deletion animation
NSMutableArray *cellsToDelete = [NSMutableArray array];
//array to track controllers to delete from presentation model
NSMutableArray *controllersToDelete = [NSMutableArray array];
//for each section
for(NSUInteger i=0; i<[tableGroups count];i++){
NSMutableArray *section = [tableGroups objectAtIndex:i];
//controllers to remove
NSMutableIndexSet *controllersToDeleteInCurrentSection = [NSMutableIndexSet indexSet];
[controllersToDeleteInCurrentSection removeIndex:0];
NSUInteger indexOfController = 0;
//for each cell controller
for(ScheduleCellController *cellController in section){
//bool indicating whether the cell controller's cell should be removed
NSString *shouldDisplayString = (NSString*)[[cellController model] objectForKey:@"filteredDataSet"];
BOOL shouldDisplay = [shouldDisplayString boolValue];
//if it should be removed
if(!shouldDisplay){
NSIndexPath *cellPath = [self indexPathOfCellWithCellController:cellController];
//if cell is on screen, mark for animated deletion
if(cellPath!=nil)
[cellsToDelete addObject:cellPath];
//marking controller for deleting from presentation model
[controllersToDeleteInCurrentSection addIndex:indexOfController];
}
indexOfController++;
}
//if removing all items in section, add section to removed in animation
if([controllersToDeleteInCurrentSection count]==[section count])
[sectionsToDelete addIndex:i];
[controllersToDelete addObject:controllersToDeleteInCurrentSection];
}
//copy the unfiltered data so we can remove the data that we want to filter out
NSMutableArray *newHeaders = [tableHeaders mutableCopy];
NSMutableArray *newTableGroups = [[allTableGroups mutableCopy] autorelease];
//removing controllers
int i = 0;
for(NSMutableArray *section in newTableGroups){
NSIndexSet *indexesToDelete = [controllersToDelete objectAtIndex:i];
[section removeObjectsAtIndexes:indexesToDelete];
i++;
}
//removing empty sections and cooresponding headers
[newHeaders removeObjectsAtIndexes:sectionsToDelete];
[newTableGroups removeObjectsAtIndexes:sectionsToDelete];
//update headers
[tableHeaders release];
tableHeaders = newHeaders;
//storing filtered table groups
self.filteredTableGroups = newTableGroups;
//filtering animation and presentation model update
[self.tableView beginUpdates];
tableGroups = self.filteredTableGroups;
[self.tableView deleteSections:sectionsToDelete withRowAnimation:UITableViewRowAnimationTop];
[self.tableView deleteRowsAtIndexPaths:cellsToDelete withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];
//marking table as filtered
self.tableIsFiltered = YES;
}
मेरा अनुमान है:
probl एम यह प्रतीत होता है: यदि आप ऊपर देखते हैं जहां मैं प्रत्येक सेक्शन में सेल्स की संख्या सूचीबद्ध करता हूं, तो आप देखेंगे कि सेक्शन 5 1 से बढ़ता प्रतीत होता है। हालांकि, यह सच नहीं है। मूल धारा 5 वास्तव में हटा दिया गया है और एक और खंड ने अपना स्थान लिया है (विशेष रूप से, यह पुराना खंड 10 है)।
तो टेबल दृश्य को यह क्यों नहीं लगता है? यह जानना चाहिए कि मैंने पुराना खंड और हटा दिया है, जो पुराने खंड की अनुक्रमणिका में स्थित एक नए खंड की अपेक्षा नहीं करनी चाहिए, जो हटाए गए अनुभाग की पंक्तियों की संख्या से बंधे रहें।
उम्मीद है कि यह समझ में आता है, यह लिखने के लिए थोड़ा जटिल है।
(नोट करें कि इस कोड ने पंक्तियों/वर्गों की एक अलग संख्या के साथ पहले काम किया था।यह विशेष कॉन्फ़िगरेशन इसे समस्याएं देता है)
वैकल्पिक रूप से, प्रत्येक सेल के लिए इंडेक्सपैथ को ट्रैक करें जिसे आप छुटकारा पाने के लिए जरूरी हैं, और जब आप अपने हटाना चाहते हैं तो उन्हें उचित रूप से समायोजित करें। (यह करने के लिए यह लंबा/गठबंधन/अनुचित तरीका हो सकता है - बस एक विचार।) – Tim
मैं बैच हटा रहा हूं, इसलिए यह उस क्रम में कोई फर्क नहीं पड़ता जिसके क्रम में मैं संचालन करता हूं। जब तालिका अद्यतन ब्लॉक में होती है तो तालिका दृश्य "एक बार में" संचालन करता है। जैसे-जैसे मैं पागल था, मैंने ऑपरेशन के आदेश को बदलने का प्रयास नहीं किया। बैच हटाने के दौरान खंड/पंक्तियों की संख्या स्विच नहीं होनी चाहिए (स्विच नहीं करना चाहिए)। यदि ब्लॉक का उपयोग नहीं कर रहा था, तो आप सही होंगे। –
@Tim दिलचस्प विचार। आप सही हैं, जो बड़ी मात्रा में हटाने (जो मेरे पास होगा) के साथ काफी कठिन हो सकता है। मुझे यह भी आश्चर्य है कि क्या मैं जल्दी उत्तराधिकार में कई विलोपन कर सकता हूं। मैं इन मुद्दों से बचने के लिए बैच हटाने की कोशिश कर रहा था, लेकिन यह आवश्यक हो सकता है। –