我有一个奇怪的问题与我的UITableViewCell子类。包含一个UITextField
和一个UILabel
。
- (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的工作…但是当我在标签上设置文本时,什么也没有显示
我想你忘记在superview上添加了。
[self addSubview:self.captionLabel];
将captionLabel
添加到单元格视图:
[self addSubview:self.captionLabel];
你需要为captionLabel设置backgroundcolor来测试它
cell.captionLabel.backgroundColor = [UIColor redColor];
[self.contentView addSubview:self.captionLabel];