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).
- (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!