0

I have some details stored inside an NSDictionary. I'm using a Master-Detail view on iPad and after I added the initWithCoder method, my app crashes on start-up and I don't know how to make it work.

The reason I want to use NSCoder is to store my user's data and be able to show it once he starts the app again. NSUserDefaults isn't feasible because I'm storing UITextFields and UISegmentedControls inside the dictionary for ease of handling data.

- (id)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super init]) {
        personInfo = [aDecoder decodeObjectForKey:myString];
    }

    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
   [aCoder encodeObject:personInfo forKey:myString];
}

Can anyone please tell me how to use it properly?

Blazer
  • 14,259
  • 3
  • 30
  • 53
Sorin Cioban
  • 2,237
  • 6
  • 30
  • 36
  • Is this other question any use? http://stackoverflow.com/questions/3943801/objective-c-how-do-i-use-initwithcoder-method – Gareth McCaughan May 13 '12 at 21:50
  • It helped a bit - it's not crashing anymore. Can you please tell me how to save that data after encoding? – Sorin Cioban May 13 '12 at 21:58
  • Probably not; I don't know a thing about Cocoa :-). But if your code is no longer crashing but you still aren't happy with what it's doing, you should probably either amend the question to reflect the new state of the world or post a new one. (If whatever was originally wrong is now fixed, you might post an answer explaining what the problem was and how you fixed it, and accept your own answer. That might be helpful to future readers.) – Gareth McCaughan May 13 '12 at 22:00

1 Answers1

0

I fixed it by simply saying

self = [super initWithCoder:aDecoder]

instead of just

self = [super init]
Sorin Cioban
  • 2,237
  • 6
  • 30
  • 36