UItableviewcell自定义单元格未显示详细信息

时间:2013-11-16 03:42:21

标签: ios

任何帮助请!!我正在尝试显示标题和详细信息,但细节不显示(空白)。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

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



    NSString * theCell = [NSString stringWithFormat:@"From %@ to %@ at %@", [flights valueForKey:@"depAirport"],[flights valueForKey:@"destAirport"],[flights valueForKey:@"depTime"]];
    NSLog(@"the %@", theCell);

    // Configure the cell...
    // Configure the cell...

    cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
    cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.textColor =[UIColor blackColor];

    cell.textLabel.text = [[flights objectAtIndex:[indexPath row]] valueForKey:@"flight_ID"];


    cell.detailTextLabel.text = theCell;


    return cell;
}

任何帮助都会很感激!!

2 个答案:

答案 0 :(得分:3)

如果您使用的是故事板,则单元格不会变为 nil 。这意味着单元格总是从dequeue方法返回。因此,您的单元格初始化代码永远不会被初始化,并且样式不会更改为 UITableViewCellStyleSubtitle 。因此,细节文本标签不存在。

因此,您必须更改故事板中的原型以获得字幕样式。

答案 1 :(得分:0)

您使用的是什么UITableViewCellStyle? UITableViewCellStyleDefault 无效。

相关问题