如何在TableView部分添加UILabel

时间:2011-01-08 08:41:15

标签: iphone uitableview

我有UITableViewController,我需要更新UILabel值。 UITableView包含部​​分。如何在TableView的左侧创建UILabel以获取更新单元格值。因为当我创建NSArray时它正在更新表右侧的值,我无法在TableView中为标签添加xib。所以请解释如何添加UILabel。它需要添加或任何其他可能性。

2 个答案:

答案 0 :(得分:0)

要创建UILabel programmaticaly,代码:

UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, 100)];

要在UILabel中显示文本,请使用:     myLabel.text = @“Lorem ......”;

当然要将UILabel添加到您的视图中:

[self.tableview addSubview:myLabel];

默认情况下,UILabel有白色背景,您可以轻松删除背景或更改颜色:

myLabel.backgroundColor = [UIColor clearColor];

答案 1 :(得分:0)

我认为你需要在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

中从UITableViewCellStyleDefault更改为UITableViewCellStyleValue1

并做

cell.detailTextLabel.text = [yourArray objectAtIndex:indexPath.row];

UITableViewCell的

Docs。祝你好运