【问题标题】:Label in Custom UITableView cell not allocated memory in iOS6自定义 UITableView 单元格中的标签未在 iOS6 中分配内存
【发布时间】:2012-12-13 01:38:13
【问题描述】:

我制作了一个自定义UITableViewCell,其中包含标签和segmentcontrol 等元素但是当我尝试访问cellforrowatindexpath 中的元素时,这些元素没有分配任何内存。单元实例已分配内存。我检查了xib并连接了插座。 这是cellforrowatindexpath中的代码-

SegmentCell *cell;
[tableView registerNib:[UINib nibWithNibName:@"SegmentCell" bundle:nil] forCellReuseIdentifier:@"SegmentCell"];
[tableView registerClass:[SegmentCell class] forCellReuseIdentifier:@"SegmentCell"];
cell = (SegmentCell *)[tableView dequeueReusableCellWithIdentifier:@"SegmentCell" forIndexPath:indexPath];
cell.title.text=@"Hell*emphasized text*o";
return cell;

标题是在打印描述中显示为 nil 的标签

【问题讨论】:

    标签: objective-c uitableview ios6 uilabel


    【解决方案1】:

    UITableViewCell 的 title 是 NSString 类型的弃用属性,而不是 UILabel。请改用titleLabel 属性。

    cell.titleLabel.text = @"whatever";

    【讨论】:

    • title 是我创建的标签的名称。抱歉应该说清楚。是不是因为名字有冲突?
    【解决方案2】:

    由于title 是您的自定义类SegmentCell 的属性,您有责任分配一个UILabel 实例并将其分配给标题。如果它包含在您的 Nib 文件中,请确保它已绑定到类属性。

    【讨论】:

      猜你喜欢
      • 2015-10-12
      • 1970-01-01
      • 2020-02-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多