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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:44:08+00:00 2026-06-03T00:44:08+00:00

I have a checkbox as an accessoryView in my UITableViewCell. When I click on

  • 0

I have a checkbox as an accessoryView in my UITableViewCell. When I click on the checkbox, it gets checkmarked and vise versa. But When i scroll down out of view and scroll back, the checkbox is gone.
I am wondering what are some ways to save the state of my button?

-(UITableViewCell *)tableView:(UITableView *)tableView
        cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = nil;

    if([tableView isEqual:self.myTableView]){
        static NSString *TableViewIdentifier = @"MyCells";
        cell = [tableView dequeueReusableCellWithIdentifier:TableViewIdentifier];
        if(cell == nil){
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
                                         reuseIdentifier:TableViewIdentifier];
        } 
        //configure the cell
        checkbox = [UIButton buttonWithType:UIButtonTypeCustom];
        CGRect checkboxRect = CGRectMake(135, 150, 36, 36);
        [checkbox setFrame:checkboxRect];  
        [checkbox setImage:[UIImage imageNamed:@"unselected@2x.png"]forState:UIControlStateNormal];
        [checkbox setImage:[UIImage imageNamed:@"selected@2x.png"] forState:UIControlStateSelected];

        /*if (checkbox.state == UIControlStateNormal) {
            [checkbox setImage:[UIImage imageNamed:@"unselected@2x.png"]forState:UIControlStateHighlighted];
        }else if(checkbox.state == UIControlStateSelected){
            [checkbox setImage:[UIImage imageNamed:@"selected@2x.png"]forState:UIControlStateHighlighted];
        }*/

        [checkbox addTarget:self action:@selector(checkboxClicked:) forControlEvents:UIControlEventTouchUpInside];
        cell.accessoryView = checkbox;


        NSString *group;
        NSUInteger row = [indexPath row];

        switch (indexPath.section) {
            case 0:
                group = [suggestedPeople objectAtIndex:row];
                cell.textLabel.text = group;
                break;
            case 1:
                group = [aArray objectAtIndex:row];
                cell.textLabel.text = group;
                break;
            case 2:
                group = [bArray objectAtIndex:row];
                cell.textLabel.text = group;
                break;
            case 3:
                group = [cArray objectAtIndex:row];
                cell.textLabel.text = group;
                break;
            case 4:
                group = [dArray objectAtIndex:row];
                cell.textLabel.text = group;
                break;
            case 5:
                group = [eArray objectAtIndex:row];
                cell.textLabel.text = group;
                break;
        }
    }
    return cell;
}

EDIT:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
    checkbox = [UIButton buttonWithType:UIButtonTypeCustom];
    CGRect checkboxRect = CGRectMake(135, 150, 36, 36);
    [checkbox setFrame:checkboxRect];  
    [checkbox setImage:[UIImage imageNamed:@"unselected@2x.png"]forState:UIControlStateNormal];
    [checkbox setImage:[UIImage imageNamed:@"selected@2x.png"] forState:UIControlStateSelected];

}
return self;}
  • 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-03T00:44:09+00:00Added an answer on June 3, 2026 at 12:44 am

    Thanks for posting the code. Right, your problem is that you are creating UIButton instances in the cellForRowAtIndexPath method. This isn’t allowed (or rather, odd things will happen as you’ve noticed). You should create a TableViewCell subclass and add the button there, or create a XIB for the table cell and load that.

    Check out this post for some help with this:

    http://forums.macrumors.com/showthread.php?t=545061

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

Sidebar

Related Questions

I have this checkBox in my view inside a form: <g:checkBox name=myCheckbox value=${false} />
T have used checkbox column in gridview. On click of a linkbutton, it should
I have a checkbox group which works fine when you tick one but it
I have a checkbox on a webpage that when you click it, updates the
I have a checkbox in a Flex DataGrid, and when I scroll, other rows
I have a checkbox, a drop down list and a text box. I want
i have checkbox list printed in one column, but i need it to print
I have Checkbox and EditText and a Textview in a listView. It gets value
I have a checkbox with an id of activelist I tried the following but
I have a CheckBox in my application that is using the TriState mode. The

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.