归档uiview控件(uiimageview,uiscrollview,uitableview,uibutton) [英] Archive the uiview controls (uiimageview,uiscrollview,uitableview,uibutton)

查看:107
本文介绍了归档uiview控件(uiimageview,uiscrollview,uitableview,uibutton)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

归档和取消归档uiview并在ipad中显示视图此控件(uiimageview,uiscrollview,uitableview,uibutton)未显示....但uiview子视图所有控件都在那里....是否有可能得到它控制(uiimageview,uiscrollview,uitableview,uibutton)在视野中?可能意味着如何让控件在视图中显示。

Am archive and unarchive the uiview and display the view in ipad this controls (uiimageview,uiscrollview,uitableview,uibutton) were not displayed....but uiview subviews all controls are there ....Is it possible to get that controls(uiimageview,uiscrollview,uitableview,uibutton) in view? possible means how to get that controls to display in view.

uiview * viewForArchive;
uiview * newCir = [uiview alloc] initwithframe:cgrectmake(0,0,768,1024)];

uiview *viewForArchive; uiview *newCir=[uiview alloc ]initwithframe:cgrectmake(0,0,768,1024)];

//存档

  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编码....

this is the uiview archiver coding....

在这个打印viewForArchive.subviews的编码中,所有的控件都存在....在我的应用程序中,这个控件(uiimageview,uiscrollview,uitableview,uibutton)没有显示...这个编码有什么问题...

In this coding to print the viewForArchive.subviews all controls are there....in my application this controls (uiimageview,uiscrollview,uitableview,uibutton) were not displayed...what is the problem in this coding...

推荐答案

如果您要保存对象的特定状态,可以存储NSUserDefaults中的字符串,并根据您的字符串设置对象。或者,您可以创建xib文件,它会自动存储您的对象吗?

If your point is to save specific states of your objects, you can store strings in the NSUserDefaults and set the objects according to your strings. Alternatively, you can create the xib files, which automatically will store your objects?

这篇关于归档uiview控件(uiimageview,uiscrollview,uitableview,uibutton)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆