Hadi Sharghi
Hadi Sharghi

Reputation: 1005

Add UI Controls to a custom TableView cell in code

I have created a custom cell for my TableView to show 1 ~ 5 rows of information in each cell. So, I have to create UILabels and UISwitches for each row of data in code, and Add them as subViews to my custom cell. I tried to add UI Controls in cellForRowAtIndexPath method before returning the custom cell with no success. Tried to add a viewDidLoad method in my customCell.m file and create controls in it, but UITableViewCell does not have a viewDidLoad method. Where should I create UIs and how can I add them to customCell?

Upvotes: 0

Views: 351

Answers (1)

LuckyLuke
LuckyLuke

Reputation: 49057

In this if you subclassed UITableViewCell:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

And add UI elements to self.contentView as subviews while you are in this function.

Upvotes: 2

Related Questions