【发布时间】:2013-11-07 17:02:59
【问题描述】:
* 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“尝试将第 0 行插入第 0 部分,但更新后第 0 部分中只有 0 行”
我意识到这里的问题是我试图向 tableView 添加一个单元格,但它不希望它不添加一个单元格,我不知道为什么。
- (IBAction)addNewIngredient: (id) sender
{
NSString *newIngredient = [recipe createIngredient];
[[recipe ingredients]addObject:newIngredient];
//figure out where that item is in the array
int lastRow = [[recipe ingredients]indexOfObject: newIngredient];
NSIndexPath *ip = [NSIndexPath indexPathForRow:lastRow inSection:0];
NSLog(@"Added a new ingredient!");
[[self tableView] insertRowsAtIndexPaths:[NSArray arrayWithObject:ip] withRowAnimation:
UITableViewRowAnimationTop];
}
为了澄清我在这里尝试做的事情:
recipe 有一个属性成分,它是一个 NSStrings 数组。 我正在向成分数组添加一个对象(这会自动增加数组计数还是我必须手动执行?)...
然后我用“int lastRow = [[recipe ingredients]indexOfObject:newIngredient]”找出该项目在数组中的位置 然后获取指向那里的索引路径。然后将该成分插入到 tableView 中。
【问题讨论】:
-
什么是
recipe?它存在吗?