*終止應用程序由於未捕獲的異常「NSInternalInconsistencyException」,理由是:「試圖插入一行0到段0,但只有0行第0更新後」insertRowsatIndexPath例外的iOS
我知道這裏的問題是我試圖添加一個單元格到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];
}
爲了澄清什麼,我想在這裏做的事:
配方有一個屬性成分是NSString的數組。 我正在添加一個對象到成分數組(這是否會自動增加數組數或我必須手動執行它?)...
然後我搞清楚那個項目在數組中的位置,用「 int lastRow = [[recipe ingredients] indexOfObject:newIngredient]「 然後獲取索引路徑指向那裏。然後將該成分插入到tableView中。
什麼是'recipe'?它存在嗎? – Wain