스토리 보드를 사용하지 않는 iOS 6 앱에서 상태 보존 및 복원을 구현하고 싶습니다. 주보기 컨트롤러는 상태를 저장하고 복원하려면 UINavigationController의 일부인 UIViewController입니다.스토리 보드없는 UIViewController 상태 복원
내보기 컨트롤러는 UIViewControllerRestoration 프로토콜을 확장합니다. 내가 필요한 모든 메소드를 구현하고 있지만 시뮬레이터에서 encodeRestorableStateWithCoder 또는 decodeRestorableStateWithCoder에 대한 호출이 표시되지 않는다고 생각합니다. MyAppDelegate :
여기 내 응용 프로그램 위임의 모습입니다
- (BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder {
NSLog(@"shouldSaveApplicationState"); // seeing this in the debug window
return YES;
}
- (BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder {
NSLog(@"shouldRestoreApplicationState"); // seeing this in the debug window
return YES;
}
- (void)application:(UIApplication *)application willEncodeRestorableStateWithCoder:(NSCoder *)coder {
NSLog(@"willEncodeRestorableStateWithCoder"); // seeing this in the debug window
}
- (void)application:(UIApplication *)application didDecodeRestorableStateWithCoder:(NSCoder *)coder {
NSLog(@"didDecodeRestorableStateWithCoder"); // seeing this in the debug window
}
내가 디버그 창에서 이러한 호출을 모두 참조하십시오. 다음은 응용 프로그램 중단에 표시 내 MyMainViewController이, 모습의 같은 :
@interface MyMainViewController : UIViewController <UIViewControllerRestoration>
@end
@implementation MyMainViewController
- (id)init {
if (self = [super init]) {
self.restorationIdentifier = @"MyViewControllerRestoreId";
self.restorationClass = [self class];
}
return self;
}
- (void)loadView {
self.view = [[UIView alloc] initWithFrame:frame];
// Bunch of work to create my custom views
}
- (void)awakeFromNib {
self.restorationClass = [self class];
}
// Expected a call to this method, but not seeing it in debug window
+ (UIViewController *)viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents
coder:(NSCoder *)coder {
NSLog(@"viewControllerWithRestorationIdentifierPath: %@", identifierComponents);
MyMainViewController *vc = [[MyMainViewController alloc] init];
vc.restorationIdentifier = [identifierComponents lastObject];
vc.restorationClass = [MyMainViewController class];
return vc;
}
// Expected a call to this method, but not seeing it in debug window
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder {
NSLog(@"encodeRestorableStateWithCoder");
[super encodeRestorableStateWithCoder:coder];
}
// Expected a call to this method, but not seeing it in debug window
- (void)decodeRestorableStateWithCoder:(NSCoder *)coder {
NSLog(@"decodeRestorableStateWithCoder");
[super decodeRestorableStateWithCoder:coder];
}
@end
내가 보존 및 복원 테스트 시뮬레이터를 사용하는 방법 : 나는 '다른 모르겠어요
1. Launch app in Simulator via Xcode
2. Invoke the Home key so App is now suspended. This where I see:
shouldSaveApplicationState
willEncodeRestorableStateWithCoder
3. End the debugging session in XCode (Command .)
4. Start a new debug session of the app in XCode. I see:
shouldRestoreApplicationState
didDecodeRestorableStateWithCoder
을 이 일을하기 위해 실종되었습니다.
작업 해 보셨습니까? 여기에 붙어있어 : –
@Jonas Gardner : 문제가 무엇인지 찾아 냈습니까?이 문제도 있습니다. 감사합니다. – Loc