I can’t seem to add this imageview to my custom uitableviewcell class and i can’t figure it out. Here is my code:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
[self layoutCell];
}
return self;
}
- (void)layoutCell
{
self.videoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 310, 120)];
[self.videoImageView setImage:[UIImage imageNamed:@"myImage.jpg"]];
[self.contentView addSubview:self.imageView];
}
In the debugger, i noticed that once i add the imageview as a subview of the contentview, the frame gets reassigned to (0,0,0,0) if that helps. I really have no idea whats going on. If anyone has any suggestions that’d be awesome. I’ve also tried adding the imageview directly to the cell’s view itself, to no avail. (and im pretty sure thats wrong anyway).
Tahnks!
Implement
layoutSubviewsmethod and check if that makes any difference. It should fix this.Update:
Try changing the
layoutCellmethod frominitmethod. Instead call it as[cell layoutCell]incellForRowAtIndexPathmethod of tableview. This will make sure that even if the dequeureuse is called while reloading, it will properly set the UIImage and frame. You can just addself.videoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 310, 120)] ;in yourinitmethod.In
cellForRowAtIndexPath,