Search code examples
uitableviewheightforrowatindexpath

UItableviewcell set custom height from inside my UITableViewCell class


Let's say i have created myTableViewCell class:

#import "MyTableViewCell.h"

@implementation MyTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{

self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
    // Initialization code

    UIImageView *imgSponsor=[[UIImageView alloc ] initWithFrame:CGRectMake(0,0,self.bounds.size.width,200)];

    imgSponsor.image = [UIImage imageNamed:@"imageFirstCell"];

    [self.contentView addSubview:imgSponsor];
}
return self;
}

[...]

@end

Can I set a default height for this cell from within this class apart from running through the associated tableviewcontroller method (heightForRowAtIndexPath..)?


Solution

  • You can use like in MyTableViewCell.h-

    -(void)layoutSubviews {  
        self.frame = //Define your frame;
    
        [super layoutSubviews];
    }