tags:

views:

87

answers:

1

Hi

I am trying to archive, unarchive objects using NSKeyedArchiver, NSKeyedUnarchiver, NSCoding (initWithCoder, encodeWithCoder methods) in order to access the last view before the application was terminated.

This works with OS 3.0 and above, but for OS 2.2.1, the objects are unarchived but a blank screen is displayed on application relaunch.

This is how I have been trying to initialize my view:

- (id)initWithCoder:(NSCoder *)decoder{
    self = [super init];
    if (self != nil)
    {
        //my code
    }
    return self;

}

I also tried using initWithNibName method as follows

- (id)initWithCoder:(NSCoder *)decoder{
    self = [super initWithNibName:@"myView" bundle:nil];
    if (self != nil)
    {
        //my code
    }
    return self;

}

But a black screen is displayed.

Can anyone please help?

+1  A: 

Actually, you should call

self = [super initWithCoder:decoder];
KennyTM
This works for OS 3.0 and above but not for OS 2.2.1 Can you please test and confirm if this works for OS 2.2.1
@user: How did you implement `-encodeWithCoder:`? It should also call `[super encodeWithCoder:encoder]` as well. Also, the file from 3.0 cannot be used on 2.2.1.
KennyTM
I am now getting this error -[UIImage encodeWithCoder:]: unrecognized selector sent to instance 0x44d6a0Any clues?
@user: You cannot encode an image. UIImage doesn't adopt NSCoding.
KennyTM
Thanks for all your help.I guess saving view state using NSKeyArchiver is not an optimal solution.I should try for other alternatives.