Search code examples
iosuitableviewinvisible

UITableViewCell, custom content invisible


When I add custom controls to a UITableViewCell (by dragging UILabel onto table cell in storyboard), the content is invisible at runtime. When I tap on the table row (to select it) the content appears, but white.

Project setup: (summary: create super-minimal storyboard project with a UITableView and a few lines of code to create content):

New project, single view application, Xcode 4.5.2, use storyboards. That creates a project targeted at iOS 6.

Drag a table view controller onto storyboard, which creates a view, the UITableView it contains, and the default UITableViewCell inside that table.

Set my table view controller as initial scene.

Set a reuse identifier string for the UITableViewCell (in storyboard editor).

Create a new file, subclass of UITableView, fill in some minimum stock data stuff to get a few rows to populate with "line XX" data text.

Run project. Data appears as expected, several rows of data saying "Line 0", "Line 1", etc. No issues.

Now, I drag a label onto my table cell in the story board. I change nothing about the properties. I leave the label text just saying "Label" in black letters.

See image at: http://www.codexlumen.com/issue/storyboard.png

Run project again.

What I expect: my table rows now have "Label" appearing in the lines, in black text.

What I actually see: exactly the same as before. The "Label" text does not appear, at all.

Now, here's the fun part:

Still running, I tap on a table row to select it. Now the row is hilighted in blue, and "Label" appears in white at the position where I placed the label control.

See image at: http://www.codexlumen.com/issue/hilight.png

So the UILabel is there, it's just not getting drawn in the non-hilighted rows...

Have no idea why.

Some other comments:

  • I am not using any kind of custom table cell subclass.
  • I didn't add anything to the project or take any steps not mentioned above.
  • I didn't change the properties of the storyboard's UITableView or UITableViewCell objects except to set the reuse identifier string and to drag the UILabel onto the cell
  • I tried running both on my 4s and int he simulator (with simulator set to various device/os configurations)
  • I've tried changing the label properties (black background, green text, etc). No effect. Visual behavior is identical no matter what properties I set (though "Label" is bigger if I enlarge text)

This is 100% storyboards. I'm creating no UI objects in code. The only reference to UI in code is the code to populate table cell, shown below:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"MyCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    cell.textLabel.text = [NSString stringWithFormat:@"Line %i", indexPath.row];

    return cell;
}

Solution

  • I see your problem. You accessing properties of standard UITableViewCell (i.e. cell.textLabel) while using custom cell. Just kill 3rd line to see the difference. I'd suggest you create your own outlets for every label you need and not use standard ones.