【问题标题】:What's the correct way to set the text of a UILabel that's part of an IBOutletCollection设置作为 IBOutletCollection 一部分的 UILabel 文本的正确方法是什么
【发布时间】:2012-07-01 12:47:16
【问题描述】:

我有一系列构成 IBOutletCollection 一部分的 UILabel

@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *labelCollection;

我已将 UILabels 的标签按顺序设置为 0、1、2、3 ...,并按标签号对 *labelCollection 进行了排序。因此,IBOutletCollection 数组中的对象“0”是带有标签“0”等的 UILabel。

使用以下函数,我可以在特定的 obj/tag 处更新 UILabel 的文本:

- (void) updateLabelAtTag:(int)objId {
        [[self.labelCollection objectAtIndex:objId] setText:@"my new text"]; 
    }

}

这很好,但是,当您在 IDE 中单击 setText: 时,Xcode Quick Help 会报错

setText:
@property(nonatomic, copy) NSString *text
iOS (2.0 and later) 
Deprecated: Use the textLabel and detailTextLabel properties instead.
The text of the cell.
UITableViewCell.h

对于我的生活,我无法弄清楚 UITableViewCell 与这种情况有什么关系。我当然无法访问 textLabel 或 detailTextLabel 属性。

问题:我是在使用已弃用的属性,还是在这种情况下 Xcode 弄错了?

【问题讨论】:

    标签: objective-c ios uilabel iboutletcollection


    【解决方案1】:

    Xcode。我怀疑

     [(UILabel *)[self.labelCollection objectAtIndex:objId] setText:@"my new text"]; 
    

    会让它消失。

    【讨论】:

    • 是的!你是对的。我应该考虑投它。 +1 更多咖啡。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-06
    • 1970-01-01
    • 2017-12-17
    • 1970-01-01
    • 2021-12-06
    相关资源
    最近更新 更多