0

Have have created a child of UITableViewCell, MenuItem which contains functionality for my custom table cell. I have also created a xib-file with a custom cell and set the UITableViewCell in the xib-file to have the class MenuItem. The name of the xib-file is MenuItem as well. In my UITableViewController class I'm doing this in ViewDidLoad:

UINib *menuItems = [UINib nibWithNibName:@"MenuItem" bundle:nil];
[[self tableView] registerNib:menuItems forCellReuseIdentifier:@"MenuItem"];

But the background color used in the xib-file isn't used in the cells the table displays. If I add a new label, it shows up, but the background color is just plain white. Does anyone know why?

EDIT: I do use [tableView dequeueReusableCellWithIdentifier:@"MenuItem"]; in cellForRowAtIndexPath.

ptf
  • 3,210
  • 8
  • 34
  • 67
  • Check out this link MAy be It will help you... [enter link description here][1] and http://stackoverflow.com/questions/281515/how-to-customize-the-background-color-of-a-uitableviewcell [1]: http://stackoverflow.com/questions/5166747/why-doesnt-uitableviewcell-background-color-work-set-in-interface-builder – Sudha Tiwari Jan 21 '13 at 10:29
  • Thanks, found my answer there. – ptf Jan 21 '13 at 11:05

1 Answers1

0

Thanks to Sudha for links to the answer.

It turns out you can't set the background color in the xib-file. You have to do it in the willDisplayCell of the delegate. Read http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html, outlined box close to the top.

ptf
  • 3,210
  • 8
  • 34
  • 67