user278859
user278859

Reputation: 10519

cell.detailTextLabel.text not working... why

Using the following code I am getting the text.label but not the detailTextLabel.text. The NSLog is displaying correctly.

cell.textLabel.text = [eventLabels objectAtIndex:indexPath.row];  
cell.detailTextLabel.text = [eventFields objectAtIndex:indexPath.row]];  

NSLog(@"%@", [eventFields objectAtIndex:indexPath.row]);  

I also tried...

cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", [eventFields objectAtIndex:indexPath.row]];     

I have not had problems with this before. Any suggestions?

John

Upvotes: 33

Views: 27922

Answers (3)

Kamille
Kamille

Reputation: 433

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                   reuseIdentifier:CellIdentifier] autorelease];
}

Do remember to change to UITableViewCellStyleSubtitle

Upvotes: 24

Erhan Demirci
Erhan Demirci

Reputation: 4209

If you choose style UITableViewCellStyleSubtitle , your detailTextLabel.text will show

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

UITableView Source

Upvotes: 2

jbrennan
jbrennan

Reputation: 12003

Make sure you're using an appropriate UITableViewCellStyle with this (anything but UITableViewCellStyleDefault should thus work). The cell's style is specified when you initialize it.

Upvotes: 84

Related Questions