【问题标题】:UITableViewCell textlabel content not displaying anythingUITableViewCell textlabel 内容不显示任何内容
【发布时间】:2014-02-10 18:14:10
【问题描述】:

我有一个 UITableView,我正在加载数据。标题显示正常,但 cell.textlabel.text 没有显示任何内容。 (注意点击时颜色不是白色,它也不会显示)但是我可以在 AlertView 中获取cell.textlabel.text 的值。

有什么帮助吗??

代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"cellT";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    cell.textLabel.text = [[theTArray objectAtIndex:indexPath.section]objectAtIndex:0];
    // Configure the cell...
    cell.textLabel.textColor = [UIColor blackColor];
    return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{

    return [[theTArray objectAtIndex:section]objectAtIndex:1];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    NSString *message = [NSString stringWithFormat:@"%@", cell.textLabel.text];
    NSString *title = [[theTArray objectAtIndex:indexPath.section]objectAtIndex:1];

    UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [tableView reloadData];


    [theAlert show];
}

图片: http://imgur.com/a/lcwyf

【问题讨论】:

    标签: ios objective-c uitableview xcode5


    【解决方案1】:

    确保你的 cell.textLabel 有宽度和高度。

    尝试调用 [cell.textLabel sizeToFit];设置文字后。

    【讨论】:

      【解决方案2】:
      cell.textLabel.text = [[theTArray objectAtIndex:indexPath.section]objectAtIndex:0];
      

      您的索引有问题。您的意思是 indexPath.row 而不是零索引吗? 在当前实现下,部分中的所有单元格都将具有相同的标题。

      【讨论】:

      • 不,我用的是多维数组
      • 好的,在分配给cell.textLabel.text之前记录文本。你会得到什么?
      • 2014-02-10 19:37:28:816 RGZH[63632:1803] -[TermineViewController tableView:cellForRowAtIndexPath:] [第 88 行] 文本:Maturitätsarbeit,Meldung ausstellungswürdiger Maturitätsarbeiten...(确切地说它应该是什么)
      • 你能说明你是怎么记录的吗,也许你应该在设置文本之前设置颜色?
      • 看看我的回答(是的,我知道我很笨)
      【解决方案3】:

      确保您返回正确的numberOfRowsInSection

      -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
      
          return [self.theTArray count];
      }
      

      cellForRowAtIndexPath

      NSString *messageAtIndexPath = [[theTArray objectAtIndex:[indexPath row]]objectAtIndex:0];
      

      确保您的委托和数据源都已设置。

      【讨论】:

      • 两个都试过了,也没用。注意:部分标题显示正常。所以datasource应该没问题吧??
      【解决方案4】:

      我在数组中的每个文本的第一个字符处都有一个换行符。所以删除它,现在一切正常。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-09-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-29
        • 2020-11-10
        • 2012-04-12
        相关资源
        最近更新 更多