行を挿入しようとすると、次のエラーが発生し続けます。
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
*** First throw call stack:
(0x31fe82a3 0x39ccc97f 0x31f33b75 0x8d18f 0x33fee5a9 0x33edb0c5 0x33edb077 0x33edb055 0x33eda90b 0x33edae01 0x33df9421 0x31fbd6cd 0x31fbb9c1 0x31fbbd17 0x31f2eebd 0x31f2ed49 0x35af62eb 0x33e44301 0xa49d 0x3a103b20)
libc++abi.dylib: terminate called throwing an exception
ここで何が起こっているか知っている人はいますか?
これが私のコードです:
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(editingStyle == UITableViewCellEditingStyleDelete)
{
Caseload *deletedCaseload = [self.caseload objectAtIndex:indexPath.row];
[self.caseload removeObject:deletedCaseload];
[self.caseloadTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
else if
(editingStyle == UITableViewCellEditingStyleInsert)
{
Caseload *copiedEntry = [self.caseload objectAtIndex:indexPath.row];
Caseload *newEntry = [[Caseload alloc]init];
newEntry.name = copiedEntry.name;
newEntry.address = copiedEntry.address;
newEntry.phoneNumber = copiedEntry.phoneNumber;
newEntry.identNumber = copiedEntry.identNumber;
[self.caseload addObject:newEntry];
[self.caseloadTableView insertRowsAtIndexPaths:
[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationRight];
}
}