「クライアント」と「車」の2つのエンティティがあるコアデータスタックがあります。どちらもtableViewControllerによって表されます。コアデータビューアでエラーが発生しました
最初のtableViewControllerがクライアントのリストを取得し、一度選択すると、2番目のクライアントはクライアントが所有する車のリストを表示します。両方がナビゲーションコントローラにプッシュされます。私が2番目のviewcontrollerから「戻る」に行くと、プログラムはfirstviewcontrollerを正常に表示し、2秒間待ってからクラッシュします。私が「ビルドしてデバッグ」したとき、コンソールにこのエラーが表示されました:
Program received signal: “EXC_BAD_ACCESS”.
私はそれを理解していません。どこでエラーを見つけるべきですか?
EDIT:メモリの処理が不良であるかどうかを確認するために、いくつかのコードを追加しました。コメントアウトされたメソッドと、エラーが発生する前に使用されなかったメソッドをすべて削除しました。
これは、あなたが所有していないオブジェクトを解放している...これは私のClientCarsViewController実装です...
@implementation ClientCarsViewController
@synthesize carsArray;
@synthesize coreDataModel;
@synthesize client;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.title = client.name;
// Get client's cars
NSSet *cars = client.cars;
// Import them into the carsArray
[self setCarsArray: [NSMutableArray arrayWithArray:[cars allObjects]]];
[cars release];
}
-(void)addCarToClient {
[coreDataModel addCarToClient:(Client *)client];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
return YES;
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [carsArray count];
}
// Customize the appearance of table view 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] autorelease];
}
// Configure the cell...
Car *car = (Car *)[carsArray objectAtIndex:indexPath.row];
cell.textLabel.text = [car carName];
return cell;
[car release];
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
}
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
self.carsArray = nil;
}
- (void)dealloc {
[self.client release];
[self.coreDataModel release];
[self.carsArray release];
[super dealloc];
}
@end
通常、このエラーは、割り当てられていないもの、または割り当てが解除されているものにアクセスしようとしていることを意味します。その2分後にアプリがクラッシュした後は何をしていますか?エラーに関する追加情報はありませんか? – sch
私は何もしません、私は戻って2秒ほど待ってから、それはクラッシュし、私にそのエラーを与えます。さらに詳しい情報はありません。私は、私がその時点で持っていけないオブジェクトをリリースしたと仮定することができます。私の投稿を編集して、それが役立つかどうかを確認するコードを貼り付けてください... –
この種のエラーについては、NSZombieEnabled環境変数を有効にすることができます。これは、あなたが到達しようとしている解放されたオブジェクトを識別するのに役立ちます。 – aslisabanci