iOS: Adding a third label to UITableViewCell without creating a Custom cell?

Mo Moosa picture Mo Moosa · Jul 29, 2012 · Viewed 9.2k times · Source

I've worked with custom cells before but I just wondered for adding a third label (nothing else!) is there a simpler solution? All I want to do is show the title, content and date. I've set the first two to the textLabels and detailTextLabels but I of course need a third for date.

So, is there a simpler solution without making a custom cell?

Thanks

Answer

Jon picture Jon · Jul 29, 2012

See A Closer Look at Table-View Cells, section called Programmatically Adding Subviews to a Cell’s Content View.

mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 220.0, 15.0)] autorelease];
mainLabel.tag = MAINLABEL_TAG;
mainLabel.font = [UIFont systemFontOfSize:14.0];
mainLabel.textAlignment = UITextAlignmentRight;
mainLabel.textColor = [UIColor blackColor];
[cell.contentView addSubview:mainLabel];