【问题标题】:TableViewCell 's textLabel and detailTextLabel is not workingTableViewCell 的 textLabel 和 detailTextLabel 不起作用
【发布时间】:2013-09-10 17:33:02
【问题描述】:

命令 cell.textLabel.text 和 cell.detailTextLabel.text 在控制台中提供输出,但在模拟器上的表格视图中没有给出任何值...

这是生成我用过的单元格的代码..

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

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

  // Book *bookDetail=[booksArrayDataSource objectAtIndex:indexPath.row];


    cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;

    cell.textLabel.text= [self titleForRow:indexPath];
    NSLog(@"title for row= %@", cell.textLabel.text);

    cell.detailTextLabel.text= [self subtitleForRow:indexPath];
    NSLog(@"subtitle for row= %@",cell.detailTextLabel.text);

    return cell;
}

【问题讨论】:

  • 像这样用 [NSString stringWithFormat:@"%@",[self titleForRow:indexPath]] 测试。
  • 尝试应用一些颜色和字体...
  • 使用 titleForRow 和 subtitleForRow 方法更新您的查询。
  • 嘿 Ganapathy 他们工作正常..因为控制台显示 NSLog(@"title for row= %@", cell.textLabel.text);NSLog(@"subtitle for row= % @",cell.detailTextLabel.text);显示标题和副标题已正确设置...但是在模拟器上看不到它们...
  • 检查一次委托方法。行数和没有。选择是否正确返回。

标签: ios objective-c uitableview


【解决方案1】:

转到您的故事板/xib 并将单元格类型从动态更改为字幕。

无论你在这里有什么,都不会被执行:

if (cell == nil)
{
...
}

【讨论】:

    【解决方案2】:

    如果您在单元格中加载字符串值,请使用以下语句:

    cell.textLabel.text =[[YOURArray_Name objectAtIndex:indexPath.row] stringValue]; (or)
    cell.textLabel.text =[[YOURArray_Name objectAtIndex:indexPath.row] description];
    

    如果您在单元格中加载整数值,请使用以下语句:

    cell.textLabel.text =[[YOURArray_Name objectAtIndex:indexPath.row] integerValue];
    

    如果您在单元格中加载浮点值,请使用以下语句:

    cell.textLabel.text =[[YOURArray_Name objectAtIndex:indexPath.row] floatValue];
    

    【讨论】:

    • 当然。您将 intfloat 分配给 NSString 属性。那不会编译。
    猜你喜欢
    • 2011-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-10
    • 1970-01-01
    • 1970-01-01
    • 2018-10-30
    • 1970-01-01
    相关资源
    最近更新 更多