次のように UITableView にデータを入力している NSMutableDictionary を含む .plist ファイルがあります。
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *myFile = [[NSBundle mainBundle]
pathForResource:@"courses" ofType:@"plist"];
courses = [[NSMutableDictionary alloc] initWithContentsOfFile:myFile];
courseKeys = [courses allKeys];
}
と:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Course";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
NSString *currentCourseName = [courseKeys objectAtIndex:[indexPath row]];
[[cell textLabel] setText:currentCourseName];
return cell;
}
UiTableView セルを使用して、ユーザーがスワイプ + 削除し、新しいアイテムを plist に「追加」できるようにしようとしています。これは私がこれを行うために使用しているコードです:
- (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
シミュレーターを実行してこれを行うと、次のエラーが表示されます
「無効な更新: セクション 0 の行数が無効です。更新後の既存のセクションに含まれる行数 (7) は、更新前にそのセクションに含まれる行数 (7) に等しい必要があります。プラスまたはマイナスそのセクションから挿入または削除された行数 (0 挿入、1 削除) と、そのセクションに移動された、またはそのセクションから移動された行数 (0 移動、0 移動) をプラスまたはマイナスします。
誰か助けてくれませんか?