2012-05-02 95 views
0

即时将2个文本添加到表格的单元格中。我在做什么是将UIView添加到单元格的子视图中,UITableViewController

UITableViewCell * cell = nil;

NSString * CellIdentifier = @“Cell”;

cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];

如果(细胞==无){

细胞= [[ALLOC的UITableViewCell] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];

[[UILabel alloc] initWithFrame:CGRectMake(80.0,0.0,220.0,10.0)];

mainLabel.tag = 1003;

mainLabel.text = @“Text 1”;

mainLabel.textAlignment = UITextAlignmentLeft;

mainLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight; [cell.contentView addSubview:mainLabel];

}

我做secondLabel添加到细胞同样的事情。 什么是在模拟器上显示为 enter image description here

现在的问题是2的UILabel的背景不与单元格的背景相同的(我的细胞在表视图分组)

有谁知道如何解决这个问题。

任何意见在这里欢迎 感谢

回答

1

如果我有很好地理解这个问题,你需要删除的UILabel的背景,因为你要显示的UITableViewCell背景来代替。所以我认为你只需要做到这一点:

mainLabel.backgroundColor = [UIColor clearColor]; 
+0

谢谢。那是我正在寻找的。 – tranvutuan

1

像上面的答案,你应该为这两个视图设置相同的颜色。

cell.backgroundColor = [UIColor clearColor]; 

或者您可以设置您设置的视图的颜色。

相关问题