Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In UITableView, cell.detailTextLabel.text isn't working… why?

In tableView:cellForRowAtIndexPath: I have the following:

cell.textLabel.text = @"label"; cell.detailTextLabel.text = @"detail"; 

The textLabel shows as expected, but the detailTextLabel doesn't appear at all, although there is no diagnostic. What I expected was that the "detail" text would appear in the cell on a second line, below the "normal" text, possibly with a smaller font size.

The same question is asked in another posting here and user "jbrennan" answered that the tableview cell style must be something other than UITableViewCellStylePlain. However, it seems there are only two possible styles, UITableViewCellStylePlain and UITableViewCellStyleGrouped. I get the same result with either (the detail label doesn't appear).

Is there another cell style that I'm not seeing in the documentation? Did UITableView change in the last update and detailTextLabel is no longer available? Do I have to do something extra to make it appear? Any suggestions?

I'm using xcode 3.2.5 and building for iPhone 4.2 Simulator.

like image 777
RobertL Avatar asked Jan 29 '11 00:01

RobertL


People also ask

Why doesn't the detail text appear in the uitableviewcontroller?

The detail (subtitle) text does not appear. The data are available, though, because when a println () call is added, it prints Optional ("data") to the console with the expected data. In the storyboard, the UITableViewController is set to the proper class, the Table View Cell Style is set to 'Subtitle', and the reuse identifier is set to 'cell'.

What is a uitableviewcell?

The visual representation of a single row in a table view. A UITableViewCell object is a specialized type of view that manages the content of a single table row. You use cells primarily to organize and present your app’s custom content, but UITableViewCell provides some specific customizations to support table-related behaviors, including:

How do I create a secondary label for a uitableviewcell?

UITableViewCell automatically creates the secondary (detail) label if the cell is created with a UITableViewCellStyle that supports a detail label. If the cell's style doesn't support a detail label, this property returns null.


1 Answers

Your initialization needs to be changed to this:

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
reuseIdentifier:CellIdentifier] autorelease];

I've emphasized and bolded the part you need to change.

like image 111
Aurum Aquila Avatar answered Sep 19 '22 16:09

Aurum Aquila