Ramsel Ramsel - 1 year ago 109
Objective-C Question

UITableViewCell setSelected:animated: not working

This is driving me crazy. I've looked here on S.O. for what I thought was a simple answer but couldn't find one.

In my custom


- (void)setSelected:(BOOL)selected animated:(BOOL)animated
// Configure the view for the selected state
if (selected) {
[self.languageLevelNameLabel setTextColor:[UIColor blackColor]];
else {
[self.languageLevelNameLabel setTextColor:[UIColor colorMessageCountZero]];

[self setNeedsDisplay];

of the controller:

if ([level integerValue] == indexPath.row) {

[cell setSelected:YES];

I've inserted break points and
selected == YES
is getting passed for the correct cell, and the
statement is being executed when it should be, but the text never gets set to

Answer Source

If you want to set your cell as selected use the method selectRowAtIndexPath:animated:scrollPosition: like this in your cellForRowAtIndexPath method of your table view

[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];