How to use Custom Static UITableViewCells to display images in cell?
ios, uitableview
Solution
I don't see anywhere where you reference the .xib file for your custom cell in `MyCustomCell.m`. You have to tell the class which .xib file to load.
Check out the following tutorial, which demonstrates one method to load the cell from the .xib file (within the custom cell class): Creating custom UITableViewCell from XIBs – step by step tutorial
This question shows another method (within `cellForRowAtIndexPath`): how to create custom tableViewCell from xib
Also, you're not really using static cells if you're recreating them in `cellForRowAtIndexPath`. You'll lose anything you've setup in Interface Builder. Consider abandoning the static cells. You can just setup all the cell properties in the same place you set the image.
Finally, if you do abandon the static cell approach consider creating your custom cell within the same view controller as your table view (the standard `UITableView` has a placeholder cell for this purpose) and dequeue the custom cell the standard way. Then, there is no additional .xib to load, so it will be handled automatically. See my previous answer for more details on creating a custom table view cell like this.
Problem
I have a tableview with 5 static cells. They are static because there will always only be 5 of them in the tableview. I want them custom cells because I need to center UIImageViews in each cell because they will have button images and nothing else. I created a MyCustomCell class with a UIImageView outlet and connected it to the outlet. Then in the tableview controller class I did this: ``` #pragma mark - TableView Cell Methods - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MyCustomCell *cell = [[MyCustomCell alloc] init]; switch (indexPath.row) { case 0: // Use Custom Cell cell.thumbnailImageView.image = [UIImage imageNamed:@"button.png"]; break; case 1: [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; // USE IMAGE INSTEAD cell.thumbnailImageView.image = [UIImage imageNamed:@"button1.png"]; break; case 2: cell.thumbnailImageView.image = [UIImage imageNamed:@"button2.png"]; break; case 3: cell.thumbnailImageView.image = [UIImage imageNamed:@"button3.png"]; break; case 4: cell.thumbnailImageView.image = [UIImage imageNamed:@"Search.png"]; break; default: break; } return cell; } ``` MyCustomCell.m: ``` - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { } return self; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated{ [super setSelected:selected animated:animated]; // Configure the view for the selected state } ``` The cells show up blank. It worked fine when instead of MyCustomCell i was using UITableViewCell. So Im not sure why its failing now.