जब भी मेरे पास UITableView
में डेटा होता है और मैं हटाना शुरू करता हूं, तो यह ठीक काम करता है। हालांकि, जब मैं तालिका में अंतिम वस्तु पर जाता हूं, और इसे हटा देता हूं, तो यह क्रैश हो जाता है।NSInternalInconsistencyException (पंक्तियों की अमान्य संख्या)
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
if ([myData count] >= 1) {
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[myData removeObjectAtIndex:[indexPath row]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *somepath = [documentsDirectory stringByAppendingPathComponent:@"something.plist"];
[myData writeToFile:somepath atomically:YES];
[table reloadData];
if ([myData count] == 0) {
[tableView endUpdates];
[tableView reloadData];
}
else {
[tableView endUpdates];
}
}
}
}
और यह भी इस:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
if ([myData count] != 0) {
return [myData count];
}
else {
return 1;
}
}
कारण मैं 1 लौटने कर रहा हूँ है, क्योंकि मैं बना रहा हूं
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 (1) 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, 1 deleted).'
यहाँ कैसे मैं संपादन कर रहा हूँ सामान है एक सेल जो cellForRowAtIndexPath
में "कोई डेटा सहेजा नहीं गया" कहता है। यहां मेरा मतलब है:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if ([cityData count] != 0) {
//normal setup removed for clarity
}
else {
cell.textLabel.text = @"No saved data!";
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
cell.textLabel.textAlignment = UITextAlignmentCenter;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.tag = 1;
return cell;
}
}
तो, मैं इस त्रुटि को प्राप्त करने के लिए अपने संपादन कोड में क्या गलत कर रहा हूं? धन्यवाद!
बिल्कुल सही, धन्यवाद! –
आप क्या कर सकते हैं केवल कॉल टेबल देखें हटाएं RowAtIndexPaths यदि [डेटा गिनती]> 0 और बाद में कॉल पुनः लोड करेंडेटा। इस तरह आप अंतिम सेल को "डेटा" सेल के लिए उपयोग करने जा रहे हैं और पुनः लोड करने से यह सुनिश्चित होता है कि प्रतिनिधि तालिकादृश्य में सही जानकारी लोड करता है। – EeKay
धन्यवाद, इससे मुझे भी मदद मिली! –