将 UILabel 添加到 UITableViewCell 的detailTextLabel

发布于 2024-09-10 08:06:23 字数 308 浏览 5 评论 0原文

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

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

但它显示错误...

我该如何解决这个问题

In my app that consist of a grouped tableView,the detailTextLabel displays dates entered through a datepicker. and i use this dates to retrieve data from webservice. What i want to do is to add UILabels to detailTextLabel of the cells so that i can access the label's text property to get the dates and send request to webservice. i tried adding label to the detailTextLabel like this

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

But its showing me error...

How can i fix this

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不寐倦长更 2024-09-17 08:06:23

您应该设置 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];

You should set cell.detailTextLabel.text to modify it's contents, and possibly change the layout of cell.detailTextLabel, but not try to assign another UILabel to it.

You might want to add your own label as a subview, then do something along the lines of

    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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文