将UILabel添加到UITableViewCell的detailTextLabel

时间:2010-07-15 10:23:52

标签: iphone uilabel

在我的应用程序中,由一个分组的tableView组成,detailTextLabel显示通过日期选择器输入的日期。我使用此日期从webservice检索数据。我想要做的是将UILabel添加到单元格的detailTextLabel,以便我可以访问标签的text属性来获取日期并向webservice发送请求。我尝试将标签添加到detailTextLabel,就像这样

cell.detailTextLabel = self.fromDate //fromDate is an instance of UILabel;

但它显示我的错误......

我该如何解决这个问题

1 个答案:

答案 0 :(得分:1)

您应该设置cell.detailTextLabel.text来修改它的内容,并可能更改cell.detailTextLabel的布局,但不要尝试为其分配另一个UILabel。

您可能希望将自己的标签添加为子视图,然后按照

的方式执行操作
    UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(160.0f,23.0f,150.0f,20.0f)];
    lbl.textAlignment = UITextAlignmentRight;
    lbl.font = [UIFont fontWithName:@"Arial" size:14.0f];
    lbl.textColor = [UIColor lightGrayColor];
    lbl.text = [@"Ref.No. " stringByAppendingString:refno];

    [cell addSubview:lbl];
相关问题