私のUITableViewのデータソースとしてNSMutableDictionaryがあります。私は、削除モードを実装しようとしている問題がある。NSMutableDictionaryからオブジェクトを削除するときのEXC_BAD_ACCESSエラー
私は削除しようとしているキーと、それが対応しているオブジェクトが、割り当てられていないメモリや何かにアクセスしようとしているように見えます。 commitEditionStyle:forRowAtIndexPath:ここでのtableViewの私の実装です
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source.
NSArray * keys = [userList allKeys];
NSNumber *keyToRemove = [keys objectAtIndex:indexPath.row];
NSLog(@"Key to remove: %@",keyToRemove);
NSLog(@"Object at key: %@",[userList objectForKey:keyToRemove]);
[userList removeObjectForKey:keyToRemove];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[keys release];
[keyToRemove release];
}
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.
}
}
このメソッドが実行され、その後、私はエラーを取得します。 2つのNSLogステートメントは、正しいキーとそれに対応する値を出力します。
私が間違っていることを誰かに教えてもらえますか?あなたがそれらを解放するべきではありませんので、あなたは、keys
かkeysToRemove
を所有していない
おかげ
おっと..彼らは割り当てられていない..私はそれを読んだ..単にばかだ。ありがとう! – Nick
割り当てられていますが、割り当てられていません。 – EmilioPelaez
私は理解しています... – Nick