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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:43:07+00:00 2026-06-16T23:43:07+00:00

I have a UITableViewController that shows a list of items from NSMutableArray, along with

  • 0

I have a UITableViewController that shows a list of items from NSMutableArray, along with a button that serves as a check box that the user can select/deselect. I am able to successfully display the table, as well as the checkboxes. However, I would like to have a tableheader at the very top of the table that would have a “select all” check box, which would allow the user to select all of the cells, or deselect all of the cells. If some cells are already checked off, then I want only those cells that are not selected, to be selected.

Here is the code that I have thus far:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        testButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [testButton setFrame:CGRectMake(280, 57, 25, 25)];
        [testButton setImage:[UIImage imageNamed:@"CheckBox1.png"] forState:UIControlStateSelected];
        [testButton setImage:[UIImage imageNamed:@"CheckBox2.png"] forState:UIControlStateNormal];
        [testButton setUserInteractionEnabled:YES];
        [testButton addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];
        [cell setAccessoryView:testButton];

    }

    // Configure the cell...
    TestObject *tObject = [[DataModel sharedInstance].testList objectAtIndex:indexPath.row];
    cell.textLabel.text = tObject.testTitle;

    return cell;

}

-(void)buttonTouched:(id)sender
{
    UIButton *btn = (UIButton *)sender;

    if( [[btn imageForState:UIControlStateNormal] isEqual:[UIImage imageNamed:@"CheckBox1.png"]])
    {
        [btn setImage:[UIImage imageNamed:@"CheckBox2.png"] forState:UIControlStateNormal];
        // other statements
    }
    else
    {
        [btn setImage:[UIImage imageNamed:@"CheckBox1.png"] forState:UIControlStateNormal];
        // other statements
    }

}

//Here is the additional method that I have added to my code to select all
-(void)clickOnCheckButton {

    NSLog(@"Did it select?");

    for (int i = 0; i < [self.tableView numberOfSections]; i++) {
        for (int j = 0; j < [self.tableView numberOfRowsInSection:i]; j++) {
            NSUInteger ints[2] = {i,j};
            NSIndexPath *indexPath = [NSIndexPath indexPathWithIndexes:ints length:2];
            UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
            //Here is your code
            [self buttonTouched:nil];

        }
    }
}

Does anyone have any suggestions on how to do this?

Thanks in advance to all who reply.

  • 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-16T23:43:09+00:00Added an answer on June 16, 2026 at 11:43 pm

    Take another NSMUtableArray as SelectedArray

    in didselectRowAtIndexPath row You can Add remove objects from SelectedArray.

    You can select a cell calling table view’s selectRowAtIndexPath method:

    [yourtable selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
    

    Put for loop for selectedArray to putcheckbutton only in selected cells.

    in Your CellForRow Method Use this

    testButton.tag=indexpath.row;
    

    you can select All row and All Section by below method.

    for (int i = 0; i < [ptableView numberOfSections]; i++) {
        for (int j = 0; j < [ptableView numberOfRowsInSection:i]; j++) {
            NSUInteger ints[2] = {i,j};
            NSIndexPath *indexPath = [NSIndexPath indexPathWithIndexes:ints length:2];
                UITableViewCell *cell = [ptableView cellForRowAtIndexPath:indexPath];
               //Here is your code
    
          UiButton *btn = (UiButton*)[cell.contentView viewWithTag:j]
    
    if( [[btn imageForState:UIControlStateNormal] isEqual:[UIImage imageNamed:@"CheckBox1.png"]])
        {
            [btn setImage:[UIImage imageNamed:@"CheckBox2.png"] forState:UIControlStateNormal];
            // other statements
        }
        else
        {
            [btn setImage:[UIImage imageNamed:@"CheckBox1.png"] forState:UIControlStateNormal];
            // other statements
        }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITableViewController that displays cells that are just default. Each cell can
I have made a XML parser that list correctly in the UITableViewController. It passes
I have a subclass of UITableViewController. I have code that can add/remove a UISearchBar
I have a UITableViewController that has a UITableView whose cells have a button attached
I have a simple UITableViewController in a UINavigationController that displays a list of strings
I have a UITableViewController subclass that renders a list of pre-set categories and fetches
I have a UITableViewController that I would like to have a left nav button,
I have a UITableViewController that pops up a UIImagePickerController, user takes a pic, hits
I have a navigation controller that works with two UITableViewControllers. The first UITableViewController shows
I have an UITableViewController , set up so that users can delete rows. This

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.