У меня есть секционированный UITableView, использующий словари, адаптирующие код из учебника (на данный момент у меня нет ссылки на меня, но я могу выкопать ее, если она вам действительно нужна).
В любом случае я пытаюсь удалить элемент из списка, когда получаю эту ошибку (предупреждение: длинная)
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 (2) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).
I В некотором роде получить информацию о количествестрок, но я точно знаю, как это исправить.
Если вы хотите увидеть информацию об отладчике, я вставлю ее в буфер, потому что она такая длинная: http://pastebin.com/0difSEnM
Вот мой код:
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)index {
NSDictionary *dictionary = [data objectAtIndex:index.section];
NSMutableArray *array = [NSMutableArray arrayWithArray:[dictionary objectForKey:@"My Wishlists"]];
NSString *selectedWishlist = [array objectAtIndex:index.row];
//now remove the item
[array removeObjectAtIndex:index.row];
[data removeObjectAtIndex:index.section];
NSDictionary *newdictionary = [NSDictionary dictionaryWithObject:[NSArray arrayWithArray:array] forKey:@"My Wishlists"];
[data insertObject:newdictionary atIndex:0];
// [data addObject:newdictionary];
[mainTableView reloadData]; // tried without and with this, no difference
[mainTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationTop];
}
Спасибо!Кристиан Стюарт