Search code examples
objective-ciosuilabeliboutletcollection

What's the correct way to set the text of a UILabel that's part of an IBOutletCollection


I have a series of UILabels that form part of an IBOutletCollection

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

I have sequentially set the tags of the UILabels to 0,1,2,3 ... and I have sorted the *labelCollection by tag number. Thus, object '0' in the IBOutletCollection array is the UILabel with tag '0' etc.

Using the following function I can update the text of the UILabel at a particular obj/tag:

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

}

This works fine, however, when you click on the setText: in the IDE, Xcode Quick Help complains

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

For the life of me I can't figure out what UITableViewCell has to do with this situation. I certainly don't appear to be able to access the textLabel or detailTextLabel properties.

Question: Am I using a deprecated property, or has Xcode got it wrong in this instance?


Solution

  • Xcode. I suspect

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

    would make it go away.