0

This code compiles fine without warnings but the substring does not appear in the cells. Any idea why?

TableExampleViewController.m

#import "TableExampleViewController.h"

@implementation TableExampleViewController

@synthesize colorNames;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

 - (void)viewDidLoad
{
    [super viewDidLoad];
    self.colorNames = [[NSArray alloc] initWithObjects:@"Red", @"Green", @"Blue",     @"Indigo", @"Violet", nil];
}

 // Customize the number of rows in the table view
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section     {
     return [self.colorNames count];
}

// Customize the appearance of table view cells
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView 
                         dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
     cell = [[UITableViewCell alloc]
     initWithStyle:UITableViewCellStyleDefault 
    reuseIdentifier:CellIdentifier];
}

     // Configure the cell
    UIImage *cellImage = [UIImage imageNamed:@"apple.png"];
                      cell.imageView.image = cellImage;
    NSString *colorString = [self.colorNames
                       objectAtIndex:[indexPath row]];

    cell.textLabel.text = colorString;
    NSString *subtitle = [NSString stringWithString:@"All about the color "];
    subtitle = [subtitle stringByAppendingString:colorString];
    cell.detailTextLabel.text = subtitle;

    return cell;
}
pdenlinger
  • 3,897
  • 10
  • 60
  • 92

1 Answers1

1

Change:

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

To:

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

The default style doesn't have a detailTextLabel.

XJones
  • 21,959
  • 10
  • 67
  • 82