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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:58:15+00:00 2026-06-17T08:58:15+00:00

I have a UITableViewController that has a UITableView whose cells have a button attached

  • 0

I have a UITableViewController that has a UITableView whose cells have a button attached to them via the accessoryView. These buttons can be selected/deselected when the user clicks on them. The table itself is made up from an NSMutableArray of objects that contain multiple NSString parameters, with the “name” parameter being on display in the table.

What I am trying to do now is when the button is selected, to add the corresponding OBJECT that links to the respective "name" parameter to an NSMutableArray. The user is not selecting the cell, but rather, they are clicking on the button that is attached to the cell.

Here is my method that selects/deselects the button in each 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];
        // statement to add object to NSMutableArray
    }
    else
    {
        [btn setImage:[UIImage imageNamed:@"CheckBox1.png"] forState:UIControlStateNormal];
        // statement to remove object from NSMutableArray
    }

}


//Here is my code that shows how I initialize my button and cell in my UITableView

- (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];
        [testButton setTag:cell.tag];
        [cell setAccessoryView:testButton];
        //[cell setAccessoryType:UITableViewCellAccessoryCheckmark];

    }

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

    return cell;

}

My issue is not so much the actual adding of an object to the array, but deriving the respective cell from the button, and then deriving the correct object from that 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-17T08:58:16+00:00Added an answer on June 17, 2026 at 8:58 am

    You need a way to link your cell to your button when you do it like this, you have a few options

    1- Set tags on the button to be the corresponding index of the element in your array, that way you can get a hold of the cells through the tag property, this can have issues if you are deleting cells as you have to update your button tags.

    2- Use a dictionary to map your buttons to your cells

    So if you use the tag to mark the index you can use cellForRowAtIndexPath of UITableViewCell to get a hold of the cell , the data object should be in your datasourcce array with that index too..
    Daniel

    • 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 a UITableViewController that contains a table, whose cells I wish to add
I have an iPad app that has a UITableViewController that implements the NSFetchedResultsControllerDelegate .
I have 8 cells that are being built in my UITableViewController. I would like
I have a UITableView that I want to edit inside of a UITableViewController. This
I have a subclass of UITableViewController. I have code that can add/remove a UISearchBar
In my iPhone app I have a UIViewController that has a UITableView and another
I have a UITableViewController that has a UISearchbar in its header view. When the
I have a UITabBarController that has 3 tabs. Each tab contains a UITableViewController. When
I have a simple UITableviewController that used to work fine and now something has

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.