try this:
CustomCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
profilePhoto = [UIButton buttonWithType:UIButtonTypeCustom];
UIColor *borderColor = [UIColor redColor];
profilePhoto.clipsToBounds = YES;
profilePhoto.layer.cornerRadius = 30;
profilePhoto.layer.borderColor = borderColor.CGColor;
profilePhoto.layer.borderWidth= 1.5f;
profilePhoto.backgroundColor = [UIColor clearColor];
[self.contentView addSubview: profilePhoto];
}
}
- (void)layoutSubviews {
[super layoutSubviews];
profilePhoto.frame = CGRectMake(5.0, 8.0, 60.0, 60.0);
}
in cellForRowAtIndexPath
, profilePhoto
must be nil for first time. because cell layoutSubviews
will be called later where you init profilePhoto
.
And as you commented, scroll will reuse the cell which have call layoutSubviews
then cell have profilePhoto
object , so the image set in cellForRowAtIndexPath
can be seen after scroll.