views:

84

answers:

1

In my method to set labels in my cells (for a UITableView) I'm reading in 'id' thats actually a UITableViewCell since I'm reading in several different types of cells. ie.

-(void)setMyCell:(id)cell atIndexPath:(NSIndexPath*)indexPath;

Some of the cells are the generic UITableViewCellStyle type while others are more complicated and load a nib etc. for the different sections.

To access a UILabel text property for my custom cells I can do something like

[(CustomCell*) cell setMyTextLabel:@"text"];

and I can create a method in CustomCell class to set the label text.

For the generic cells the label is called 'textLabel'. I think I can do something like

[(UITableViewCell*) cell setTextLabel:<new UILabel here>];

but that seems somewhat messy as I need to create a new UILabel.

I tried

(UITableViewCell*)cell.textLabel.text = @"text";

which would work if cell was of class UITableViewCell, not id, but it doesnt in this case.

So is there any way to just set textLabel.text without creating a new UILabel?

A: 

Have you tried adding a category to UITableViewCell with your label-changing method, and then overriding that method in CustomCell?

Shaggy Frog