コードの更新: Matthew の回答に続いて、コードをより正確に修正しようとしました。コードはセルを削除しますが、クラッシュしてエラーが発生します。
* キャッチされていない例外 'NSInvalidArgumentException' が原因でアプリを終了しています。理由: '* -[__NSPlaceholderArray initWithObjects:count:]: オブジェクト [0] から nil オブジェクトを挿入しようとしています'
checkboxTapped
以下のコードは、私のコードで呼び出されたアクションからのものCustomCell
です。アクションが起動されると、エラーが発生します。myindexPath
が に等しいことがわかりましたNULL
。これが問題である可能性が最も高いです。しかし、私はそれを修正する方法がわかりません。
[self.textLabel setTextColor:[UIColor grayColor]];
[self.detailTextLabel setTextColor:[UIColor grayColor]];
parent = [[ViewController alloc] init];
db = [[DataObject alloc] init];
NSIndexPath *indexPath = [[parent tableView] indexPathForSelectedRow];
[[parent array] removeObjectAtIndex:[indexPath row]];
[db deleteTaskAtIndex:[indexPath row]];
[[parent tableView] deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[db release];
[parent release];
Old:コードを調べて、使用していた配列を印刷しました。問題ないように見えますが、このエラーは引き続き発生します。
* キャッチされない例外 'NSRangeException' が原因でアプリを終了します。理由: '* -[__NSArrayM removeObjectAtIndex:]: 境界を超えたインデックス 1 [0 .. 0]'
私の推測では、それは私と関係があると思われましたが、私indexPath
がどれだけ変更してもそれほど違いはありません.
-(void)checkboxTapped:(id)sender
{
[sender setSelected:YES];
[self.textLabel setTextColor:[UIColor grayColor]];
[self.detailTextLabel setTextColor:[UIColor grayColor]];
parent = [[ViewController alloc] init];
UITableView *tableView = parent.tableView;
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:parent.array];
[parent release];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[array count] inSection:1];
[array removeObjectAtIndex:[indexPath row]];
[db deleteTaskAtIndex:[indexPath row]];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
[array release];
[tableView endUpdates];
[tableView reloadData];
}