Archive the uiview controls (uiimageview,uiscrollview,uitableview,uibutton)

与世无争的帅哥 提交于 2020-01-14 03:37:09

问题


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)];

//archiving

  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!");

     }

this is the uiview archiver coding....

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


回答1:


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?



来源:https://stackoverflow.com/questions/9494685/archive-the-uiview-controls-uiimageview-uiscrollview-uitableview-uibutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!