モーダルビューコントローラを使用してUItableViewにユーザー定義のテキストを追加しています。 テーブルはNSMutableArrayとして作成されます。モーダル・ビューでデータを入力し、完了ボタンをタップすると無効な更新が行われました。無効な更新:無効なセクション数。エラーが生成されます。 ユーザーがデータを入力したときに配列を更新する必要がありますが、その方法はわかりません。関連するコードを添付しました。アドバイスありがとうございます。あなたは既に配列にこれを追加したい場合を除き<NSInternalInconsistencyException>無効な更新:無効なセクション数
int newRowIndex = [listOfConjProcedures indexOfObject:item];
これは、インデックスを持っていないだろうが、次の行に、あなたはそれを追加します。
//Number of sections
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }
//Number of rows
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [listOfConjProcedures count];
}
//Loading the cells
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell.
cell.textLabel.text = [listOfConjProcedures objectAtIndex:indexPath.row];
return cell;
}
//Done button Delegate for the modal view
- (void)itemDetailViewController:(ItemDetailViewController *)controller didFinishAddingItem:(ChecklistItem *)item
{
int newRowIndex = [listOfConjProcedures indexOfObject:item];
[listOfConjProcedures addObject:item];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:newRowIndex inSection:0];
NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
[self dismissViewControllerAnimated:YES completion:nil];
}
numberOfSectionsメソッドの外観はどうですか? – jrturton
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } – MacUser