I have hair pulling. I'm just trying to create a table with a UITableViewCellStyleSubtitle style with text and details. But the details do not appear. This usually happens because someone forgot to initialize the cells with the correct style, but this is not what happens in this case. I tried all four cell styles and the details are not displayed in any of them, although the text label moves to the right when I use UITableViewCellStyleValue2.
I have successfully created tables many times before. The only significant difference I can come up with in this case is that I do not use the UITableViewController. Instead, I embed a UITableView, like any other view, and connect my own data source and delegate.
I applied the key method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Get the UITableViewCell (out of the recycling pool, or de novo) NSString *reuseID = @"CELL"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID]; if (not cell) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:reuseID] autorelease]; } cell.textLabel.text = @"Foo"; cell.detailTextLabel.text = @"Bar"; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.detailTextLabel.frame = CGRectMake(10, 20, 200,22); // required cell.detailTextLabel.font = [UIFont boldSystemFontOfSize:12]; // also required //[cell setNeedsLayout]; (makes no difference) return cell; }
I can see the text text only if I include the BOTTOM of the “required” lines above (and use any cell style other than Default), and even when I do this, the position of the text label completely covers the position of the part label.
So it looks like the initializer creates the detailTextLabel UILabel, but sets its font size to zero and its frame to something empty or off-screen. (I tried to check them in the debugger, but this is not very useful - the font size is zero, and the frame is empty for BOTH textLabel and detailTextLabel, but textLabel is always displayed normally.)
Obviously, I can get around this if necessary by manually adjusting the sizes and fonts. But it bothers me that I need to do this in this case, when usually you just set the style, and the text and layout are automatic. I searched googles and, but cannot find a link to a similar problem. Does anyone know what is going on here?
(Testing for iOS 6.1.)