代码之家  ›  专栏  ›  技术社区  ›  user278859

cell.detailtextlabel.text不工作…为什么

  •  33
  • user278859  · 技术社区  · 16 年前

    使用下面的代码,我得到的是text.label,而不是detailtextlabel.text。nslog显示正确。

    cell.textLabel.text = [eventLabels objectAtIndex:indexPath.row];  
    cell.detailTextLabel.text = [eventFields objectAtIndex:indexPath.row]];  
    
    NSLog(@"%@", [eventFields objectAtIndex:indexPath.row]);  
    

    我也试过…

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

    我以前没有遇到过这样的问题。有什么建议吗?

    约翰

    3 回复  |  直到 9 年前
        1
  •  84
  •   jbrennan    16 年前

    确保你用的是合适的 UITableViewCellStyle 带着这个 UITableViewCellStyleDefault 因此应该有效)。单元格的样式在初始化时指定。

        2
  •  24
  •   Alex Cio Olie    12 年前
    - (UITableViewCell *)tableView:(UITableView *)tableView 
             cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                       reuseIdentifier:CellIdentifier] autorelease];
    }
    

    别忘了换成 uitableViewCellStyleSubtitle

        3
  •  2
  •   helion3    12 年前

    如果你选择风格 UITableViewCellStyleSubtitle 你的 detailTextLabel.text 将展示

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

    UITableView Source