Search code examples
objective-cuitableviewarchive

Obj-c initWithCoder seems to crash NavigationController


does anyone know why when i add...

-(id) initWithCoder: (NSCoder *) decoder {

    OutputDataMutableArray = [[decoder decodeObjectForKey:@"RootViewControllerPostArray"] retain];

    return self;

}

to my RootViewController it will not push a new view from a table cell using the didSelectRowAtIndexPath method. This is the line it seems to hang on...

[[self navigationController] pushViewController:postController animated:YES]; 

i get no error messages, it just seems to skip it. Unless i take the initWithCoder out and it works fine.

any insight would be appriciated.

Chris


Solution

  • You’re not calling the superclass’s implementation of -initWithCoder:.

    - (id)initWithCoder:(NSCoder *)aDecoder
    {
        self = [super initWithCoder:aDecoder];
    
        if(self)
        {
            OutputDataMutableArray = [[decoder decodeObjectForKey:@"RootViewControllerPostArray"] retain];
        }
    
        return self;
    }