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 8608457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:36:58+00:00 2026-06-12T03:36:58+00:00

I created a custom cell using interface builder, it has two labels and one

  • 0

I created a custom cell using interface builder, it has two labels and one UIButton. I have no problem setting the text of each label inside cellForRowAtIndexPath or willDisplayCell. However, setting the image of the UIButton has issues in either place. I think the issues are related to cell re-usage/caching that I don’t fully understand.

Here is my current code that mostly uses willDisplayCell, but I have also tried moving most of the code to cellForRowAtIndexPath with the same results:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIButton *check = (UIButton*) [cell.contentView viewWithTag:1];
    UIButton *check2 = (UIButton*) [cell.selectedBackgroundView viewWithTag:1];
    UILabel *from = (UILabel*) [cell.contentView viewWithTag:2];
    UILabel *subject = (UILabel*) [cell.contentView viewWithTag:3];

    // Configure the cell...
    Message *rec = (Message*) Records[indexPath.row];
    if(rec.Checked)
        check.imageView.image = [UIImage imageNamed:@"Checkedbox.png"];
    else
        check.imageView.image = [UIImage imageNamed:@"Checkbox.png"];
    check2.imageView.image = check.imageView.image;
    from.text = rec.From;
    subject.text = rec.Subject;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    return cell;
}

In the above code, check2 is nil, I’ve tried without that as well, but just recently added that as an attempt to fix.

I’m basically building a message list (inbox) and want checkboxes like GMail has. In the click event for the checkbox button I have:

- (IBAction)CheckClicked:(id)sender
{
    UITableViewCell *cell = (UITableViewCell*) [[sender superview] superview];
    NSIndexPath *indexPath = [[self tableView] indexPathForCell:cell];
    Message *rec = (Message*) Records[indexPath.row];
    rec.Checked = !rec.Checked;
    [cell setNeedsLayout];
    [cell.contentView setNeedsLayout];
    [cell setNeedsDisplay];
    [cell.contentView setNeedsDisplay];
    [self.tableView reloadData];
}

I know all of the setNeedsLayout and setNeedsDisplay calls above are redundant, I mostly just have them there to show what didn’t work. Only reloadData would at least redraw/refresh each cell, even though most examples say setNeedsLayout on the cell should have worked.

What happens is the checkboxes change correctly when clicked, however if I checkmark one cell, then I click to highlight the cell, the checkbox is unchecked until the view scrolls off-screen and then back. I assumed the problem is related to there being different views for selected vs not-selected, but beyond that not sure what to check.

Edit: As most tutorials use code similar to this, here is what I have also tried, but in this usage the image never changes until cells are scrolled off and back on screen, even though I can set breakpoints and see that the cellForRowAtIndexPath is being called for each cell again after reloadData is called in my click event, and it is correctly setting the image to checked for the item I checked:

- (IBAction)CheckClicked:(id)sender
{
    UITableViewCell *cell = (UITableViewCell*) [[sender superview] superview];
    NSIndexPath *indexPath = [[self tableView] indexPathForCell:cell];
    Message *rec = (Message*) Records[indexPath.row];
    rec.Checked = !rec.Checked;
    [self.tableView reloadData];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    // NOTE: In my testing cell is never NULL, so I have no checking here.

    UIButton *check = (UIButton*) [cell.contentView viewWithTag:1];
    UILabel *from = (UILabel*) [cell.contentView viewWithTag:2];
    UILabel *subject = (UILabel*) [cell.contentView viewWithTag:3];

    // Configure the cell...
    Message *rec = (Message*) Records[indexPath.row];
    if(rec.Checked)
        check.imageView.image = [UIImage imageNamed:@"Checkedbox.png"];
    else
        check.imageView.image = [UIImage imageNamed:@"Checkbox.png"];
    from.text = rec.From;
    subject.text = rec.Subject;

    return cell;
}
  • 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-12T03:37:00+00:00Added an answer on June 12, 2026 at 3:37 am

    Not sure if this is a good answer, but it appears to work and maybe is the way Apple intended for things to be.

    I got the idea from another SO answer UITableViewCell Reuse and Images Re-render where they used multiple prototypes for each different style.

    So instead I created 2 prototype cells in IB, one with the checked image, and one with the unchecked image. Then updated my code to this:

    - (IBAction)CheckClicked:(id)sender
    {
        UITableViewCell *cell = (UITableViewCell*) [[sender superview] superview];
        NSIndexPath *indexPath = [[self tableView] indexPathForCell:cell];
        Message *rec = (Message*) Records[indexPath.row];
        rec.Checked = !rec.Checked;
        [self.tableView reloadData];
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        Message *rec = (Message*) Records[indexPath.row];
    
        UITableViewCell *cell;
        if(rec.Checked)
            cell = [tableView dequeueReusableCellWithIdentifier:@"CheckedCell"];
        else
            cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    
        UILabel *from = (UILabel*) [cell.contentView viewWithTag:2];
        UILabel *subject = (UILabel*) [cell.contentView viewWithTag:3];
    
        from.text = rec.From;
        subject.text = rec.Subject;
    
        return cell;
    }
    

    All I can figure is the “reused” cell supports certain changes, but not others. So it supports different text in UILabel controls, but does not support different images in UIButton controls. I have read about people finding issues with certain properties like background colors and font styles, so maybe this is just another issue along those lines.

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

Sidebar

Related Questions

I have created a custom cell for loading into a table. The interface is
I have created a UITableView with a custom UITableViewCell . My cell includes one
I have created custom cell in which there are n number of image views.
I have a custom tableview cell created programmatically that consists of: a background view
I have created custom posts and I want one page in my site to
I'm using a custom UITableViewCell I've created to expand a cell when it's touched.
i have created custom Cell in a controller CustomCellController. The custom Cell Contains a
I have created a custom cell with its own .m, .h and .xib file.
I have a custom cell that has a button on it. I would like
I've created a custom cell class using these instructions: http://www.bdunagan.com/2009/06/28/custom-uitableviewcell-from-a-xib-in-interface-builder/ Everything worked great, except

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.