Reputation: 315
For my UITableViewController in my Storyboard I created a custom cell, with several text labels, which I want to represent the different data in my records. How do I select the various textlabels (I set each of the labels I want to change with different tags but not sure where to go from here) to change.
Upvotes: 2
Views: 2249
Reputation: 104092
You can do this with tags, but I usually prefer to do this with a custom subclass of UITableViewCell. You only need to define some IBOutlets in your custom class's .h file -- you don't need any code at all in the .m file. Change the class of the cell to your subclass, and hook up the outlets to your labels in the cell. Then in code, you can refer to them just like you do for a standard cell. If your outlets were label1 and label2, then:
cell.label1.text = ....
cell.label2.text = ...
If you want to use tags, then you can use the method, viewWithTag: to get a reference to the label.
UILabel = *aLabel = (UILabel *)[cell.contentView viewWithTag:1];
Upvotes: 5