编辑:我似乎找到了一些有用的东西。我保留了IVAR的“堆栈”,现在它似乎在工作
我已经连续化了几个自定义nsObject类,没有问题。现在我想序列化我的导航控制器堆栈。为了重建导航树,每个视图控制器只需要保存几个属性。我已经在视图控制器中实现了nscoding协议,并成功地将它们编码为nsdata并保存到磁盘。
当我尝试加载堆栈时,得到的数组具有正确的对象数,但是当我尝试设置viewcontroller数组时,我总是得到exc ou bad ou访问错误。我是不是走错了路?
-(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 = [[decoder decodeObjectForKey:@"stack"]retain];
[decoder release];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
NSLog(@"%@",self.navigationController.viewControllers);
if ([stack count] > 1) {
self.navigationController.viewControllers = stack;
[stack release];
}
return YES;
}