我正在使用状态恢复为我的应用程序恢复以前的视图和数据。当在第一个视图控制器中单击一个按钮时,我将推送第二个视图控件。在这种情况下,我可以恢复第二个视图控制器数据。但是如果我添加第二个当在第一个视图控制器中单击按钮时,将视图控制器视图作为第一个视图控制器的子视图,在第二个视图控制器中未调用 encodeRestorableStateWithCoder:和 decodeRestorableStateWithCoder:。无法恢复第二个视图控制器数据。我需要做任何其他配置来恢复子视图数据 ?
//Firstviewcontroller
-(IBAction)moveToNextViewController:(id)sender {
SecondVeiwController *sec_VC=[[SecondVeiwController alloc]initWithNibName:@"SecondVeiwController" bundle:[NSBundle mainBundle ]];
sec_VC.restorationIdentifier=@"SecondVeiwController";
[self.view addSubview:tab_cnt_1.view];
}
//Secondviewcontroller
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.restorationIdentifier=@"Secondviewcontroller";
self.restorationClass=[self class];
}
return self;
}
+(UIViewController *)viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder
{
UIViewController * myViewController =
[[Secondviewcontroller alloc]
initWithNibName:@"Secondviewcontroller"
bundle:[NSBundle mainBundle]];
return myViewController;
}