Я разрабатываю приложение IOS. Удалите строку в таблице и загрузке данных в основных данных в виде таблицы. Нажмите кнопку «Удалить». Причина Причина: Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (18) must be equal to the number of rows contained in that section before the update (18), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out)...
Удалить строку из таблицы вид
_fetchedobj является NSArray для извлечения данных из основных данных
//Code is
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _fetchedobj.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyReuseIdentifier";
UITableViewCell *cell = [myTable dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
data = [_fetchedobj objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[tableView beginUpdates];
NSManagedObject *managedObject = [_fetchedobj objectAtIndex:indexPath.row];
[self.managedObjectContext deleteObject:managedObject];
[myTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[myTable endUpdates];
}
}
Что делает вашу реализацию '-tableView: cellForRowAtIndexPath:' выглядеть ? – jperl
Если вы не выполняете '[_fetchedobj removeAtIndex: indexPath.row]' в delete? В противном случае вы не обновили модель данных, используемую для определения количества строк. –