【问题标题】:Archive the uiview controls (uiimageview,uiscrollview,uitableview,uibutton)归档 uiview 控件(uiimageview、uiscrollview、uitableview、uibutton)
【发布时间】:2012-03-18 16:15:01
【问题描述】:

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

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 归档器编码....

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

【问题讨论】:

  • 我无法让您发送代码或明确问题?

标签: objective-c uiview ios5


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    相关资源
    最近更新 更多