पर काम नहीं कर रहा है और उसे हटा रहा है, मुझे उसी UITableView से UITableViewCells को डालने और हटाने में काफी दर्द हो रहा है!UITableViewCell को एक ही समय में
मैं सामान्य रूप से कोड पोस्ट नहीं है, लेकिन मुझे लगा कि यह दिखा, जहां मैं समस्या आ रही है का सबसे अच्छा तरीका था:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 5;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (iSelectedSection == section) return 5;
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//NSLog(@"drawing row:%d section:%d", [indexPath row], [indexPath section]);
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
if (iSelectedSection == [indexPath section]) {
cell.textColor = [UIColor redColor];
} else {
cell.textColor = [UIColor blackColor];
}
cell.text = [NSString stringWithFormat:@"Section: %d Row: %d", [indexPath section], [indexPath row]];
// Set up the cell
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic -- create and push a new view controller
if ([indexPath row] == 0) {
NSMutableArray *rowsToRemove = [NSMutableArray array];
NSMutableArray *rowsToAdd = [NSMutableArray array];
for(int i=0; i<5; i++) {
//NSLog(@"Adding row:%d section:%d ", i, [indexPath section]);
//NSLog(@"Removing row:%d section:%d ", i, iSelectedSection);
[rowsToAdd addObject:[NSIndexPath indexPathForRow:i inSection:[indexPath section]]];
[rowsToRemove addObject:[NSIndexPath indexPathForRow:i inSection:iSelectedSection]];
}
iSelectedSection = [indexPath section];
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:rowsToRemove withRowAnimation:YES];
[tableView insertRowsAtIndexPaths:rowsToAdd withRowAnimation:YES];
[tableView endUpdates];
}
}
इस कोड को 5 वर्गों बनाता है, पहली पंक्ति (0 से अनुक्रमित) 5 पंक्तियों के साथ। जब आप कोई सेक्शन चुनते हैं - यह उस अनुभाग से पंक्तियों को हटा देता है जिसे आपने पहले चुना था और आपके द्वारा चुने गए अनुभाग में पंक्तियां जोड़ती हैं।
छवि यहाँ:
Pictorally, जब मैं एप्लिकेशन को लोड, मैं इस तरह कुछ है http://www.freeimagehosting.net/uploads/1b9f2d57e7.png
धारा 2 के एक तालिका पंक्ति 0 चयन करने के बाद, मैं फिर हटाएं खंड 1 (डिफ़ॉल्ट रूप से चयनित किया जाता है) की पंक्तियों और खंड 2. की पंक्तियों को जोड़ने लेकिन मैं इस मिल:
छवि यहां: http://www.freeimagehosting.net/uploads/6d5d904e84.png
... जो मैं होने की उम्मीद नहीं करता! ऐसा लगता है कि सेक्शन 2 की पहली पंक्ति किसी भी तरह बनी हुई है - भले ही यह निश्चित रूप से हटा दी जाए।
यदि मैं सिर्फ एक [tableView reloadData] करता हूं, तो सब कुछ सामान्य के रूप में दिखाई देता है ... लेकिन मैं स्पष्ट रूप से अच्छे एनिमेशन की कल्पना करता हूं।
अगर कोई यहां कुछ प्रकाश डाल सकता है तो मैं वास्तव में इसकी सराहना करता हूं! यह मुझे थोड़ा पागल कर रहा है!
धन्यवाद, निक।
हे ईजेम्स, आपकी टिप्पणी के लिए धन्यवाद - वास्तव में मान्य बिंदु !! मैंने सोचा कि एक मिनट के लिए यह मेरी समस्या का समाधान कर सकता है - लेकिन मुझे अभी भी एक ही समस्या है। मुझे लगता है कि वास्तव में एक आईफोन हो सकता है लेकिन जब आप एक सेक्शन से वस्तुओं को आजमाते हैं और हटाते हैं और उन्हें एक ही समय में दूसरे अनुभाग में जोड़ते हैं ... –