문제

이 문제를 해결하는 방법에 대한 전문가의 조언이 필요합니다. iPad에 대한 새로운 앱을위한 조잡한 테스트를하고 있습니다.

다른 앱에서 생성 된 Plist 파일을로드하여 내 뷰 컨트롤러의 ViewDIDLOAD (내 .h 파일에 선언)에 NSMutableArray (BallPath)를 만듭니다.

ballPath = [[NSMutableArray alloc] initWithCapacity:1000];

NSString *path=[[NSBundle mainBundle] pathForResource:@"level_1" ofType:@"plist"];

ballPath = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
.

이 배열에는 이제 여러 cgPoints (다른 앱에서 nsvalues와 아카이브로 저장)를 포함합니다.

여기에 이미지 설명

i 다음 경로를 그립니다 (여전히 내 viewDidload에 있음). 따라서 경로가 잘 작동해야합니다.

나중에 배열을 가속화의 변경에 대한 응답으로 읽으려면 exc_bad_access를 얻으려고합니다. 디버깅 및 내 배열을 보면 다음과 같이 보입니다.

여기에 이미지 설명

i 테스트 및로드 된 배열을이 (viewDidload에서도) :

    ballPath = [[NSMutableArray alloc] initWithObjects:
            [NSValue valueWithCGPoint:CGPointMake(100.0, 100.0)],
            [NSValue valueWithCGPoint:CGPointMake(100.0, 200.0)],
            [NSValue valueWithCGPoint:CGPointMake(100.0, 300.0)],
            [NSValue valueWithCGPoint:CGPointMake(100.0, 400.0)],
            [NSValue valueWithCGPoint:CGPointMake(125.0, 450.0)],
            [NSValue valueWithCGPoint:CGPointMake(150.0, 500.0)],
            [NSValue valueWithCGPoint:CGPointMake(300.0, 600.0)],
            [NSValue valueWithCGPoint:CGPointMake(350.0, 550.0)],nil];
.

그런 다음 잘 작동합니다!

여기에 이미지 설명을 입력하십시오

여기에 누락 되었습니까 ????

Xcode 4.0.2에 있고 내 목표는 iOS 4.3입니다.

도움이 되었습니까?

해결책

The array is deallocated at that point, so that there's some random memory where the array previously was.

unarchiveObjectWithFile: returns an autoreleased object, if you want to keep the array around, you need to retain it (or make it a retained property). The alloc-init two lines earlier is completely superfluous (and probably leaks memory), because you're never doing anything with the array you create there, it is replaced by the array you load from the bundle.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top