Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8283777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:51:44+00:00 2026-06-08T10:51:44+00:00

I am trying to add a strikethrough label to my table cells (conditional on

  • 0

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 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:51:45+00:00Added an answer on June 8, 2026 at 10:51 am

    The problem is with the line CGRect frame = cell.textLabel.frame;
    The cell’s textLabel didn’t laid out yet, so the frame will be (0,0,0,0) and u won’t see the strikethrough label.

    The reason u see the strikethrough in the next cells is because those are the reused cells that already laid out the textLabel.

    As I see it u have two options:
    First option, set the strikethrough frame yourself, u can use sizeWithFont to figure out what is the needed width, the font should be the textFiled font. Play with it a bit to find the correct x offset so it will be exactly on the textLabel.

    - (void)addStrikethrough:(UITableViewCell*)cell
    {
        CGSize textLabelSize = [cell.textLabel.text sizeWithFont:[UIFont systemFontOfSize:20.0]];
    
        CGFloat cellHeight = cell.bounds.size.height;
        CGFloat strikethroughLabelHeight = 20.0;
    
        CGRect frame = CGRectMake(12, (cellHeight - strikethroughLabelHeight)/2, textLabelSize.width, strikethroughLabelHeight);
        UILabel *strikethrough = [[UILabel alloc] initWithFrame:frame];
        strikethrough.opaque = YES;
        strikethrough.backgroundColor = [UIColor clearColor];
        strikethrough.text = @"------------------------------------------------";
        strikethrough.lineBreakMode = UILineBreakModeClip;
        [cell.contentView addSubview:strikethrough];
    }  
    

    Second option is to subclass UITableViewCell and add the strikethrough label to it.
    then u can set it’s frame in layoutSubviews method, and u can hide/unhide this label according to your needs…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to add a custom pin for current location, However the location does not
I am trying add OR operator in awk command. The following does not work.
Im trying to add an constructor to my webservice, that looks like this: public
Am trying to add different numbers from different textbox, in a way that once
I am trying add two columns in a text file that are seperated by
Im trying to add a button in my grid view that will redirect me
I'm trying add a directory of jar files (or barring that, each jar file
I'm trying add a tab to my web page that looks like this: Using
I'm trying add some implicit rules in CMake that will generate direct dependencies (like
trying to add an ExpiresDefault ExpiresByType to content on my website so that way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.