I have a custom cell loaded from my table, with an image and a label the label shows ok but the image doesn’t show
CustomCell.m
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier: (NSString*)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code [self initLabels]; CGRect vintageScreenRect = CGRectMake(25, 0.0f, 100, 100); self.iconImage = [[UIImage alloc]init]; UIImageView *vintageScreen = [[UIImageView alloc] initWithFrame:vintageScreenRect]; //[vintageScreen setImage:[UIImage imageNamed:@"vidButtonImg.png"]]; // [vintageScreen setImage:self.iconImage]; [vintageScreen setImage:[UIImage imageNamed:self.tingo]]; vintageScreen.opaque = YES; // explicitly opaque for performance [self.contentView addSubview:vintageScreen]; [vintageScreen release]; NSLog(@"tingo ::%@", self.tingo); } return self; }
UsingTable.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell.tingo = [NSString stringWithFormat:@"picsButtonImg.png"]; cell.iconName.text = @"d"; } return cell; }
So the label shows ok , but the image doesn’t show, I have tried with sending an uiImage and an NSString,
what is missing? thanks!
self.tingoprobably is nil ininitWithStylemethod. You are asigningself.tingoproperty after initWithStyle call.That cause
[UIImage imageNamed:self.tingo]is also nil, and the image simply doesn’t exist.You can fix it for example by custom setter of tingo property, or by making vintageScreen as property and set image “from outside”.