This post is about a problem that is basic but starters are likely to fall into if not careful. When using a tableview, there will be a time when there will be a need to use custom table cell class. There will be outlets defined for views inside cell. Now there will be a time for need of initializing views. Now there is a chance of falling into one common problem when trying to initialize views of cell that is being loaded from Storyboard. What could be happening is stuff doesn’t get initialized when cell is created. Only one thing comes to mind is that init is not getting called at all. So lets see how init method looks like when xcode creates UITableViewCell subclass for us:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

Yeah so we have initwithstyle for intializing our stuff. But when we write any initializing code then it doesn’t work. Thing is that when your views are being loaded from storyboard then initWithCoder is used not initwithstyle. So what we need is this:

- (id)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if (self) {
        // Initialization code
    }
    return self;
}

Thanks.