*キャッチされない例外 '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];
}
私がここでやろうとしていることを明確にするために:
レシピには、NSString の配列である成分のプロパティがあります。成分配列にオブジェクトを追加しています (これにより、配列数が自動的に増加しますか、それとも手動で行う必要がありますか?)...
次に、「int lastRow = [[レシピの材料]indexOfObject:newIngredient]」を使用して、その項目が配列内のどこにあるかを把握しています。次に、そこを指すインデックス パスを取得します。そしてその成分をtableViewに挿入します。