Filthy Night Filthy Night - 14 days ago 5x
Objective-C Question

Multiple labels in a table cell view

I want to add three labels into a cell dynamically, cell is created dynamically as well, but I don't know how to create labels and add it into the cell in Objective-C (iPhone). Can anybody help me?


By "dynamically" I assume you mean via code, not via Interface Builder. I also assume you know how to use -tableView:cellForRowAtIndexPath:.

Then things are simple. The UITableViewCell has a readonly contentView property. You can just add your three UILabel's as a subview of contentView.

UIView* view = cell.contentView;
UILabel* label1 = [[UILabel alloc] initWithFrame:…];
[view addSubview:label1];
[label1 release];