편집 : 도움이되는 뭔가를 찾은 것 같습니다. 나는 "스택"을 보유하고 이제는 작동하는 것처럼 보입니다.NSCoding iPhone NavigationController 스택의 직렬화
나는 여러 가지 커스텀 NSObject 클래스를 문제없이 직렬화하고 있습니다. 이제 NavigationController 스택을 직렬화하고 싶습니다. 각 viewController는 탐색 트리를 다시 작성하기 위해 저장된 두 개의 특성 만 필요합니다. viewController에서 NSCoding 프로토콜을 구현하고 NSData에 성공적으로 코딩하여 디스크에 저장했습니다.
스택을로드하려고하면 결과 배열에 올바른 수의 개체가 있지만 viewController 배열을 설정하려고하면 EXC_BAD_ACCESS 오류가 계속 발생합니다. 나는 이것에 대해서 잘못 생각하고 있는가?
//AppDelegate.m
-(void) loadDataFromDisk {
NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *programDataPath = [libraryPath stringByAppendingPathComponent:@"programData.dat"];
NSData *programData = [[NSData alloc] initWithContentsOfFile:programDataPath];
NSKeyedUnarchiver *decoder = [[NSKeyedUnarchiver alloc] initForReadingWithData:programData];
//stack is a mutable array declared in header
//stack = [decoder decodeObjectForKey:@"stack"];
stack = [[decoder decodeObjectForKey:@"stack"]retain]; //retain fixes? Seems to work
[decoder release];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
NSLog(@"%@",self.navigationController.viewControllers);
if ([stack count] > 1) {
self.navigationController.viewControllers = stack;
[stack release]; //retained earlier
}
return YES;
}