xcodecrashtitlenscodinginitwithcoder

Xcode NsCoding navigation title disappears


I have added this code to the "MasterViewController.m" in my project:

- (void)encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:_savedText forKey:@"savedText"];
}

.

- (id)initWithCoder:(NSCoder *)decoder {
if((self = [super init])) {
    _savedText = [decoder decodeObjectForKey:@"savedText"];
}
return self;
}

When I added the "initWithCoder-code" the navigation title disappears and when I click the "add button" in the navigation bar the app crashes. (_savedText" is a mutableArray) What causes the problem?


Solution

  • Don't call [super init]. Call [super initWithCoder:] instead.