luca
luca

Reputation: 37136

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..)?

Upvotes: 1

Views: 591

Answers (1)

rishi
rishi

Reputation: 11839

You can use like in MyTableViewCell.h-

-(void)layoutSubviews {  
    self.frame = //Define your frame;

    [super layoutSubviews];
}

Upvotes: 1

Related Questions