33

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

jbrennan
  • 11,943
  • 14
  • 73
  • 115
user278859
  • 10,379
  • 12
  • 51
  • 74

3 Answers3

85

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.

jbrennan
  • 11,943
  • 14
  • 73
  • 115
  • That was it!!!! I was using but UITableViewCellStyleDefault. I think I used what was provided when I created the class without thinking about. Thanks so much. John – user278859 Feb 27 '10 at 23:18
  • 10
    user278859: if John has answered your question then do accept his answer. Whats the use if you dont accept even correct answers? – Parth Bhatt Nov 11 '10 at 08:26
  • @jbrennan have you filed a bug to Apple?, in their docs they say the default one can support a detailed text label... – Juan Boero Feb 26 '16 at 15:06
24
- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {

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

Do remember to change to UITableViewCellStyleSubtitle

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
Kamille
  • 433
  • 3
  • 4
2

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

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

UITableView Source

helion3
  • 34,737
  • 15
  • 57
  • 100
Erhan Demirci
  • 4,173
  • 4
  • 36
  • 44