2013-04-30 58 views
0

我有一個奇怪的問題,我的UITableViewCell的子類。它包含一個UITextField和一個UILabelUITableViewCell的子類不顯示文本

- (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;

奇怪的是,我可以在設置文本框我的作品所有的東西......但是當我設置的文字在我的標籤什麼也不顯示。

回答

1

添加您captionLabel到小區查看:

[self addSubview:self.captionLabel]; 
+0

謝謝我怎麼能沒有看到... ... – Sebastian 2013-04-30 11:47:50

3

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

[self addSubview:self.captionLabel]; 
+0

+1福氣:) – Anupdas 2013-04-30 11:48:40

+0

感謝我怎麼可能沒有看到... – Sebastian 2013-04-30 11:49:21

+1

阿斯伯格綜合症的原因,人們變得過度集中或癡迷於唱歌le object or topic,ignore all other。只是在開玩笑...歡迎兄弟...) – BhushanVU 2013-04-30 12:20:32

1

你需要重新設置groundColor爲captionLabel測試它

cell.captionLabel.backgroundColor = [UIColor redColor]; 
0
[self.contentView addSubview:self.captionLabel]; 
相關問題