I've done custom UITableViewCells before without issue.. but I can't figure out what is going on with my current project.
Here's what I've done...
- Create CustomCell.h (subclassing UITableViewCell)
- Create an empty XIB and drag in UITableViewCell. Set background to black.
- Change class of UITableViewCell in Interface Builder to "CustomCell"
- Import CustomCell.h in my DetailViewController
- Modify
tableView:cellForRowAtIndexPath:
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSLog(@"DO I GET HERE?");
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil];
cell = [topLevelObjects objectAtIndex:0];
}
I would expect my tableview cells to show as black? But they are still showing as white... any ideas? Thanks!
Update: Ok, turns out, it is loading the custom cell... I added a UILabel with some white text. I couldn't see it, but when I highlighted the cell I could see the text was there. So now the question becomes, why is the cell ignoring the black background I have set for the cell?
UIViewfrom a xib and you should set it ascell.contentView. Try setting:cell.contentView = (UIView *)[topLevelObjects objectAtIndex:0];instead ofcell = [topLevelObjects objectAtIndex:0];- Rok Jarc