Weird iOS bug with UITableViewCell and userInteractionEnabled

I just noticed something very strange with the UITableViewCell class on iOS and the userInteractionEnabled property.

It appears that if userInteractionEnabled is set to NO before assigning text to the cell label, then the text is coloured grey. However, setting userInteractionEnabled to NO after the text has been set leaves the text colour as black (see the example code fragment below).

  • Any (early) experiences with auto-renewable subscriptions for iOS
  • What is _UILayoutGuide?
  • iOS - How can I schedule something once a day?
  • Changing manually $(AppIdentifierPrefix) property?
  • UIWebView not loading JavaScript properly - Embedded Facebook post
  • iOS get physical screen size programmatically?
  • - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (!cell)
           cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        // swap these two lines around, and the text color does not change to grey!
        cell.userInteractionEnabled = (indexPath.row % 2) == 0;
        cell.textLabel.text = @"Hello";
        return cell;

    This is really annoying, because it means that I end up with a different behaviour in the case that a cell is reused. The above example demonstrates this – the first page of the table shows alternate rows with grey/black text. Scroll further down so that cells get reused, and you can see that things go wrong.

    I just wondered if I am doing something wrong, or if this is an iOS bug? I see the problem under iOS 5.1 on the iPad 3. Any insight really appreciated!

    2 Solutions Collect From Internet About “Weird iOS bug with UITableViewCell and userInteractionEnabled”

    I found that if I put cell.textLabel.textColor = [UIColor blackColor]; right before cell.userInteractionEnabled = NO; , it seems to fix the problem. This is how it is working on iOS 6.0.1

    cell.textLabel.textColor = [UIColor blackColor];
    cell.userInteractionEnabled = NO;

    I think I found a more convenient workaround for this problem (which I consider to be a bug):

    Set the enabled property on textLabel and detailTextLabel manually like this:

    cell.userInteractionEnabled = (indexPath.row % 2) == 0;
    cell.textLabel.enabled = cell.isUserInteractionEnabled;
    cell.detailTextLabel.enabled = cell.isUserInteractionEnabled;

    This led me to the answer: