Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8116575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:52:40+00:00 2026-06-06T03:52:40+00:00

I have one ViewController, in this i have added one Custom UIView named as

  • 0

I have one ViewController, in this i have added one Custom UIView named as DrawingView. I want to add dynamic number of UITextView in this DrawingView so i subclassed UITextView with class name as CustomTextView. In ViewController i have following code to add textview to DrawingView.

- (void)viewDidLoad
{
    [super viewDidLoad];
    DrawingView * newDrawingView = [[DrawingView alloc]init];
    self.drawingView = newDrawingView ;
}

-(void)setDrawingView:(DrawingView *)_drawingView
{  
    if (drawingView != _drawingView)
    {        
        [drawingView removeFromSuperview];
        drawingView = _drawingView;
        drawingView.customDelegate = self;
        drawingView.frame = scrollView.bounds;    
        drawingView.layer.cornerRadius = 8;
        drawingView.backgroundColor = [UIColor whiteColor];
        drawingView.clipsToBounds = YES;

        [self.view addSubview:drawingView];
    }
}

On button action i add the CustomTextView in the drawing view.

currentText = [[TextViewContainer alloc]init];
[drawingView currentText];

Now I want to archive this DrawingView along with its subviews i.e the CustomTextView.
So in CustomTextView i added NSCoding Protocol and added properties in it

- (id)initWithCoder:(NSCoder *)aDecoder
{
     if ((self  =  [super initWithCoder:aDecoder]))
     {
         self.layer.borderWidth  =  [aDecoder decodeFloatForKey: @"borderWidth"] ;
     }
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeFloat:self.layer.borderWidth forKey:@"borderWidth"];
}

there are other custom properties in the above methods.
For archiving i am using following methods.

- (NSData *)dataForView:(UIView *)view:(NSString *)fileName
{

    NSMutableData *data = [NSMutableData data];
    NSKeyedArchiver  *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
    [archiver encodeObject:view forKey:fileName];
    [archiver finishEncoding];

    return (id)data;
}


-(void)saveChangesInFile :(NSString *)fileName
{
    NSData *data = [self dataForView:drawingView:fileName];

    NSString *docsDirectory  =  [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

    NSString *dataPath  =  [docsDirectory stringByAppendingPathComponent:@"/.hidden"];

    if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
    {
        [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil];
    }

    NSString *pathes  =  [dataPath stringByAppendingPathComponent:fileName];

    [data writeToFile:pathes atomically:YES];
}


- (UIView *)viewForData:(NSData *)data:(NSString*)key
{
    NSKeyedUnarchiver  *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];

    UIView *view = [unarchiver decodeObjectForKey:key];

    [unarchiver finishDecoding];

    return view;
}

-(void)openSavedFileWithName:(NSString*)fileName{

    NSString *docsDirectory  =  [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

    NSString *dataPath  =  [docsDirectory stringByAppendingPathComponent:@"/.hidden"];
    NSString *filepath = [dataPath stringByAppendingFormat:@"/%@",fileName];
    NSData *data = [NSData dataWithContentsOfFile:filepath];

    if (data)
    {    
        UIView *newDrawView = [self viewForData:data:fileName];
    }
    NSLog(@"neew :%@",newDrawView.subviews);
    self.drawingView = (DrawingView *)newDrawView ;
    NSLog(@"self.drawingView :%@",self.drawingView.subviews);
}

But I am getting subview array as nil. Can anybody help me please.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:52:42+00:00Added an answer on June 6, 2026 at 3:52 am

    Think you are trying to archive a view itself.

    [archiver encodeObject:view forKey:fileName];
    

    I think its wrong. You cannot Archive any UI components but you can only archive the model.
    For example you can save the model (including the size, color and background images of the particular view) to the database and cannot save the view itself to the database. Likewise for archiving, u need to archive its data(viz, array, image, etc.) and not the UI components themselves.

    Have a look at the NSKeyedArchiver ClassReference for the further details.
    Also, please look at the link for detailed explaination.
    Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys! I have this little problem: I have one ViewController which adds 2
currently i am working in game application, Already i have one viewcontroller (and make
I have done navigation one viewcontroller to another, But when I done navigation multiple
I have created two viewController classes such that one is superclass of another.i have
Bit confused with this one so bear with me... I have a Navigation-based project
Please see this simple CATiledLayer example https://github.com/seanhess/CATiledLayer-Example It consists of one viewController with a
In my view of my iPhone app, I have added one sub view, which
I have one single MainViewController which has of course it's one main UIView. I
I have one problem with my iOS Application. I want to play multiple audio
I have a UITabBarController and want a button seen only on one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.