Am archive and unchive the uiview and display the view in ipad this controls(uiimageview,uiscrollview,uitableview,uibutton)not display。。。。但是uiview子视图所有控件都在那里。。。。有可能在视图中获取控件(uiimageview、uiscrollview、uitableview、uibutton)吗?possible表示如何在视图中显示该控件。
uiview*viewForArchive;uiview*newCir=[uiview alloc]initwithframe:crectmake(0,07681024)];
//归档
NSMutableData *d= [NSMutableData data];
NSKeyedArchiver *kA=[[NSKeyedArchiver alloc] initForWritingWithMutableData:d];
[kA encodeObject:newCir forKey:@"view"];
[kA finishEncoding];
if ([d writeToFile:[NSHomeDirectory() stringByAppendingPathComponent:@"archiveView"] options:NSAtomicWrite error:nil] == NO)
{
NSLog(@"writeToFile error");
}
else
{
NSLog(@"Written!");
}
//unarchiving
NSData *theData = [NSData dataWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"archiveView"]];
NSKeyedUnarchiver *decoder = [[NSKeyedUnarchiver alloc] initForReadingWithData:theData];
NSDictionary *dict= [decoder decodeObjectForKey:@"view"];
[decoder finishDecoding];
if ([theData writeToFile:[NSHomeDirectory() stringByAppendingPathComponent:@"unarchiveView"] options:NSAtomicWrite error:nil] == NO) {
NSLog(@"writeToFile error");
}
else {
if ([dict isKindOfClass:[UIView class]]) {
viewForArchive=(UIView *)dict;
NSLog(@"view:%@",viewForArchive.subviews );
viewForArchive.backgroundColor=[UIColor whiteColor];
[self.view addsubview:viewForArchive];
}
NSLog(@"Written!");
}
这是uiview archiver编码。。。。
在打印视图ForArchive.subview的编码中,所有控件都在那里。。。。在我的应用程序中,这些控件(uiimageview、uiscrollview、uitableview、uibutton)没有显示。。。这个编码有什么问题。。。
如果您的目的是保存对象的特定状态,则可以将字符串存储在NSUserDefaults中,并根据字符串设置对象。或者,您可以创建xib文件,该文件将自动存储您的对象?