我很难从部分删除行。当我用户选择行时,我得到indexPath,如下所示:
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_selectedIndexPath = indexPath;
// call a method that performs the deletion
}
当用户按下删除按钮
时,将调用实际的删除方法 [_groceryItems removeObject:groceryItem];
[self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:_selectedIndexPath.row inSection:_selectedIndexPath.section]] withRowAnimation:UITableViewRowAnimationAutomatic]; <-- THIS LINE BLOWS UP!
无效更新:无效的部分数量。更新后的表视图中包含的节数(2)必须等于更新前的表视图中包含的节数(3),加上或减去插入或删除的节数(0插入,0删除)。“
我做错了什么?
更新:为numberOfRowsInSection添加代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSArray *groceryItemsInCategory = [self getGroceryItemsByCategoryName:_groceryItemCategories[section] section:section];
// Return the number of rows in the section.
return [groceryItemsInCategory count];
}
-(NSArray *) getGroceryItemsByCategoryName:(NSString *) categoryName section:(NSInteger) section {
return [_groceryItems filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"groceryItemCategory.title = %@",_groceryItemCategories[section]]];
}
添加图片