Search code examples
iosobjective-cxcodeuitableviewcalayer

CALayer changes not shown up when written inside initWithCoder


I'm trying to do some CALayer stuff on a UIButton that resides inside a uitableviewcell. I've imported but the CALayer manipulation is not working. When I moved it to cellForRowAtIndexPath method it works fine. I do want to make the change once inside the class of the cell itself and not inside the table creation table. Do you have any ideas ?

By the way, I do see the NSLog text on the init (so I know it entered the block).

Thanks !

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        NSLog(@"STARTED coder init in testResultCell");
        [[self.bubbleMore layer] setMasksToBounds:YES];
        [[self.bubbleMore layer] setBorderWidth:3.0f];
        [[self.bubbleMore layer] setBorderColor:[UIColor blueColor].CGColor];
        [[self.bubbleMore layer] setCornerRadius:20.0f];
    }
    return self;
}

Solution

  • Move the code to awakeWithNib. Your outlets won't be connected yet in initWithCoder. From Apple's documentation:

    When an object receives an awakeFromNib message, it is guaranteed to have all its outlet instance variables set.