다음 방법을 호출 한 후이 예외가 발생합니다. 앱이 처음으로로드 될 때만 제공됩니다. 다시 응용 프로그램을 열면 제대로 작동합니다. 누구든지 도와 줄 수 있습니까?Exc_Bad_Access Iphone에서 데이터베이스를 만드는 중 예외가 발생했습니다.
-(void) createAndCheckDatabase
{
BOOL success;
self.databaseName = @"database.db";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [documentPaths objectAtIndex:0];
self.databasePath = [[documentDir stringByAppendingPathComponent:self.databaseName]retain];
NSFileManager *fileManager = [NSFileManager defaultManager];
success = [fileManager fileExistsAtPath:self.databasePath];
if(success) return;
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:self.databaseName];
NSError *err;
[fileManager copyItemAtPath:databasePathFromApp toPath:self.databasePath error:nil];
if (err) {
// DebugLog(@"%@", [err description]);
}
}
당신은 우리에게 다음 속성을 붙여 넣거나 표시 할 수 있습니까? : self.databaseName? 뭐야? 유지? –
@JonasSchnelli 예 그것의 보유 –
이렇게하면 메모리 누수가 발생합니다 :'self.databasePath = [[documentDir stringByAppendingPathComponent : self.databaseName] retain];'retain'을 제거하십시오. 그러나 충돌은 거기에서 오지 않아야합니다. 디버거로 메소드를 단계별로 실행 했습니까? 어디에서 추락합니까? –