Строка субтитров не отображается в ячейках - PullRequest
0 голосов
/ 20 ноября 2011

Этот код прекрасно компилируется без предупреждений, но подстрока не отображается в ячейках.Любая идея, почему?

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;
}

1 Ответ

1 голос
/ 20 ноября 2011

Изменение:

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

Кому:

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

Стиль по умолчанию не имеет detailTextLabel.

...