UITableViewCell的子类不显示文本

时间:2013-04-30 11:41:40

标签: ios objective-c uikit

我的UITableViewCell的子类有一个奇怪的问题。它包含UITextFieldUILabel

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectZero];
        self.textField = textField;
        self.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self addSubview:textField];
        [textField release];
        UILabel *captionLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        [captionLabel setFont:[UIFont systemFontOfSize:14]];
        [captionLabel setTextColor:[UIColor blackColor]];
        self.captionLabel = captionLabel;
        [captionLabel release];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.captionLabel.frame = CGRectMake(15, 10, 80, 20);
    self.textField.frame = CGRectMake(150, 10, 200, 20);
}

然后我将值设置为...... textFilterCell.captionLabel.text = textFilter.caption;

奇怪的是我可以在我的textField上设置所有可行的东西......但是当我在我的标签上设置文字时,没有任何内容显示出来。

4 个答案:

答案 0 :(得分:3)

我想你忘了在superview上添加它。

[self addSubview:self.captionLabel];

答案 1 :(得分:1)

将您的captionLabel添加到单元格视图中:

[self addSubview:self.captionLabel];

答案 2 :(得分:1)

您需要将groundColor设置为captionLabel以进行测试

cell.captionLabel.backgroundColor = [UIColor redColor];

答案 3 :(得分:0)

[self.contentView addSubview:self.captionLabel];