2012-02-29 26 views
1

我的存檔和unarchive uiview並顯示在ipad中的視圖這個控件(uiimageview,uiscrollview,uitableview,uibutton)沒有顯示....但uiview子視圖全部控制在那裏....是否有可能得到該控件(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)沒有顯示......這個編碼有什麼問題...

+0

我無法得到你可以發送代碼或明確的問題? – 2012-02-29 07:15:09

+0

嘗試放入一些代碼 – 2012-02-29 08:33:43

回答

0

如果你的觀點是保存你的對象的特定狀態,你可以將字符串存儲在NSUserDefaults中並設置根據你的字符串的對象。或者,你可以創建xib文件,它會自動存儲你的對象?