I am trying to add a strikethrough label to my table cells (conditional on a BOOL hasStrikethrough). The problem is that the strikethrough does not appear when the table is first displayed (even though hasStrikethrough == YES). If you scroll the table then the rows get redisplayed and the strikethrough appears correctly. The strikethrough is just a UILabel that is being added as a subview of the UITableViewCell.
Here is my code for cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ItemCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Item *item = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = item.itemName;
cell.textLabel.textAlignment = UITextAlignmentLeft;
cell.showsReorderControl = YES;
cell.shouldIndentWhileEditing = NO;
if ([[item hasStrikethrough] boolValue] == YES) {
[self addStrikethrough:cell];
}
return cell;
}
Here is the code for addStrikethrough:
- (void)addStrikethrough:(UITableViewCell*)cell
{
CGRect frame = cell.textLabel.frame;
UILabel *strikethrough = [[UILabel alloc] initWithFrame:frame];
strikethrough.opaque = YES;
strikethrough.backgroundColor = [UIColor clearColor];
strikethrough.text = @"------------------------------------------------";
strikethrough.lineBreakMode = UILineBreakModeClip;
[cell addSubview:strikethrough];
}
Thanks in advance :-)