每当我在<代码>上有数据时,便可读,而且我开始删除,就进行罚款。 然而,当我拿到桌上最后物体并删除时,它便坠毁。
Terminating app due to uncault particular NS InternalInconsistency Exception,êt: Invalid Update: Disability number ofrow in section 0. 更新(1)后现有一节所载行数必须等于更新(1)之前该节所载行数,加上或减去该节所插入或删除的行数(加插,1删除)。
在这里,我如何做编辑工作:
-(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;
}
}
The reason I m returning 1 is because I m making a cell that says "No data saved" in cellForRowAtIndexPath
. Here s what I mean:
-(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;
}
}
So, what am I doing wrong in my editing code to get this error? Thanks!