Reputation: 81
I have a property in the customCell.h file which is a UIImageView, i have synthesized it in the .m and added it to the contentView in the initWithFrame -
self.contentView addSubView:myImageView;
in the cellForRow method I call
customCell.myImageView.image = [UIImage imageName:@"someImageName.jpg"] like normal
The image does not get added because i'm guessing initWithFrame gets called before the image is assigned to to image view
any solutions?
Upvotes: 0
Views: 2013
Reputation: 3399
Source Example - http://www.appcoda.com/customize-table-view-cells-for-uitableview/
You can design your own custom cell using a nib(.xib) file in Interface Builder.
After that make outlets as the property to that custom cell.
Then, in cellForRowAtIndexPath:
use the following patch.
CustomTableCell *cell = (CustomTableCell*) [tableView dequeueReusableCellWithIdentifier:customTableCellId];
if(cell == nil) {
NSArray *nib = [[ NSBundle mainBundle] loadNibNamed:@"CustomTableCell" owner:self options:nil];
cell = [ nib objectAtIndex:0];
}
cell.myImageView.image = [ UIImage imageNamed: [imageArray objectAtIndex:indexPath.row]];
.....
.....
Upvotes: 1