0

編集:私は助けになった何かを見つけたようです。ivarの「スタック」を保持しましたが、現在は機能しているようです

私は問題なくいくつかのカスタムNSObjectクラスをシリアル化しています。次に、NavigationControllerスタックをシリアル化します。各viewControllerは、ナビゲーションツリーを再構築するために保存されたいくつかのプロパティのみを必要とします。私はviewControllersに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;

}

4

1 に答える 1

0

ディスクからロードした後、viewControllerスタックを保持する必要がありました。明らかに、保持されているプロパティにデータをすぐに割り当てないと、データは消えてしまいます。

于 2010-10-18T02:33:56.477 に答える