Why doesn't my UITableViewCell have a textLabel property?

I'm at a dead end (and probably blind to something incredibly obvious). I have a UITableView with which I want to do terribly normal things, for example, display text on every line. To do this, I used the usual delegate method tableView:cellForRowAtIndexPath: This is called expected. According to the docs, I have to create a UILabel object and set it as a textLabel property in a new UITableCell. But I collapsed with an unrecognized selector for setTextLabel: - the compiler properly warns me that it is not there. The legacy setText: method is used and works fine (with a warning). I definitely create against 3.0 libraries (I have no choice in disclosing other goals. Therefore, I am puzzled. What am I missing?

Thanks.

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell * cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease]; UILabel * label = [[[UILabel alloc] init] autorelease]; [label setText:@"Foo."]; [cell setTextLabel:label]; // BOOM. return cell; } 
+6
iphone uitableview
source share
2 answers

The textLabel property is marked as readonly. You should have used.

cell.textLabel.text = @ "some text";

+18
source share

You can use cell.textlabel.text = [NSString StringWithFormat: @ "% d", yourint];

0
source share

All Articles