【问题标题】:How to add UILabel in TableView section如何在 TableView 部分添加 UILabel
【发布时间】:2011-01-08 08:41:15
【问题描述】:

我有UITableViewController,我需要更新UILabel 值。 UITableView 包含部分。如何在 TableView 的左侧创建 UILabel 以更新单元格值。因为当我创建NSArray 时,它正在更新表格右侧的值,所以我无法在 xib 中添加 TableView 中的标签。所以请解释如何添加UILabel。它需要添加或任何其他可能性。

【问题讨论】:

  • 我试着稍微改进一下你问题的拼写和语法,但我不太明白你在问什么。

标签: iphone uitableview


【解决方案1】:

要以编程方式创建 UILabel,代码:

UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, 100)];

要在 UILabel 中显示文本,请使用: myLabel.text = @"Lorem...";

当然还要将 UILabel 添加到您的视图中:

[self.tableview addSubview:myLabel];

UILabel 默认为白色背景,您可以轻松移除背景或更改颜色:

myLabel.backgroundColor = [UIColor clearColor];

【讨论】:

    【解决方案2】:

    我认为您需要将- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath中的 UITableViewCellStyleDefault 更改为 UITableViewCellStyleValue1

    然后做

    cell.detailTextLabel.text = [yourArray objectAtIndex:indexPath.row];

    Docs 的 UITableViewCell。祝你好运

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多