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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:37:55+00:00 2026-05-26T00:37:55+00:00

I am having quite a bit of trouble trying to implement a checkbox as

  • 0

I am having quite a bit of trouble trying to implement a checkbox as part of a todo list.
I have a UITableView, and each UITableViewCell should have its own checkbox, on the lefthand side.

I would appreciate it if someone could show me how to accomplish this. I have looked extensively at the questions on this site and still can’t figure out how to implement this.

The issues arise when scrolling the tableview. If I have 20 todo items, for example, when I scroll, the checkboxes that are to be selected, get deselected, and the ones that are to be deselected, get selected, in a seemingly random fashion. It must be something with the scrolling.

What exactly is being cached and happening when the system reuses a cell? Am I grabbing an empty cell with just references to empty subviews inside it?

If tablecell #1 has a view with a tag of 10, will tablecell #2 be able to have a view with a tag of 10? Or are tags not to be repeated throughout the entire tableView? (I’m not even sure that this is the problem)

Thank you!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

switch (selectedSegment) {

case Todos:{

            static NSString *ToDoCellIdentifier = @"TodoTableViewCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifierToDoCellIdentifier];

            UITextView *taskTextView = nil;
            UIButton *checkBox = nil;
            UIImageView *highPriorityIcon = nil;

            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:signoutTableViewCellIdentifier] autorelease];


                checkBox = [[UIButton alloc]initWithFrame:CGRectMake(1, 1, 25, 25)];
                checkBox.tag = indexPath.row;
                UIImage *normalImage = [UIImage imageNamed: @"checkbox_unchecked@2x.png"];

                UIImage *selectedImage = [UIImage imageNamed: @"checkbox_checked@2x.png"];
                [checkBox setImage:normalImage forState:UIControlStateNormal];
                [checkBox setImage:selectedImage forState:UIControlStateSelected];

                [checkBox addTarget:self action:@selector(historyButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; 
                [cell.contentView addSubview:checkBox];
                [checkBox release];

                //cell.contentView.backgroundColor = [UIColor lightGrayColor];
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                NSLog(@"creating a new cell");

            }

            if (!checkBox) {

                checkBox = (UIButton*)[cell viewWithTag:indexPath.row];
            }


            }


            if ([[self.tasksCheckedStates objectAtIndex:indexPath.row]boolValue]) {



                checkBox.selected = YES;

            }
            else {


                checkBox.selected = NO;
            }



            return cell;
            break;
        }
  • 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-05-26T00:37:56+00:00Added an answer on May 26, 2026 at 12:37 am

    You need to do the following:

    • store the checked / unchecked status in your background data model, not just as a property of your cells. The cell is reused so you can’t use properties of the cell for persistence.
    • in your cellForRowAtIndexPath method, make sure that you uncheck your indicator (however you are implementing this) for unchecked items, as well as checking the indicator for checked items. Again, the cells are reused so a checked cell could be dequeued for an unchecked item.

    EDIT

    You posted your code as I was writing my answer! I think your problem is the tag you are assigning to the checkbox. You shouldn’t be using the index path row for this, as you will have no reference to this by the time you have scrolled down to, say, row 20. Give the checkbox the same tag for all cells and you should be ok. You use the tags to distinguish between views within a superview, so there is no problem with the checkbox having the same tag in all cells.

    A further point on your other question: when a cell is dequeued from the table, you get the original object back, with all its views and data as used for the previous time. So if you did nothing except dequeue a cell, create it if missing, then returned it, your first screenful of data would just keep repeating. The normal course of operations, which you are already following except for the tagging issue, is

    • dequeue cell
    • if no cell is returned, create a new cell and do basic, non- changing configuration
    • set up the cell for the specific row
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having quite a bit of trouble implementing unit testing on the
I'm having quite a bit of trouble with something that should be really simple.
I've been having quite a bit of trouble trying to make a deep copy
I'm quite new to sql and I'm having trouble writing this i have a
I having some trouble trying to figure out how to implement a Rails 3
I'm having quite a bit of trouble replacing the newline and carriage return characters
I'm having quite a bit of trouble linking a test project of FLTK I'm
I'm a beginning programmer and I've been having quite a bit of trouble with
I am having quite a bit of trouble getting mini_magick to draw text that
I'm having a bit of trouble trying to get class association's to work correctly.

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.