【发布时间】:2014-05-26 13:28:20
【问题描述】:
我正在使用状态恢复来恢复我的应用程序以前的视图和数据。当在第一个视图控制器中单击一个按钮时,我将推动第二个视图控件。在这种情况下,我能够恢复第二个视图控制器数据。但是如果当在第一个视图控制器中单击按钮时,我将第二个视图控制器视图作为子视图添加到第一个视图控制器,在第二个视图控制器中未调用 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;
}
【问题讨论】:
标签: ios state-restoration