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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:33:09+00:00 2026-06-12T18:33:09+00:00

I have seen some posts before, but didn’t get the answer yet, thats why

  • 0

I have seen some posts before, but didn’t get the answer yet, thats why i am trying to post again in more effective manner. How can i use check-uncheck functionality in UITableView like below image.

This is table i want when i click on button of any cell, that buttons image will change, not on all cells.

table

  • 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-12T18:33:10+00:00Added an answer on June 12, 2026 at 6:33 pm

    For Check-Uncheck functionality only buttonClicked: method is not enough. You will have also put the condition in cellForRowAtIndexPath: method for which button is selected or which in unselected because cellForRowAtIndexPath: method will call each time when you will scroll your UITableView and cells will be refresh.
    And i saw your previous question you’re adding two buttons with two action not a good way just change the image of button for check-uncheck.

    So here is what i do for this –

    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>
    {
        IBOutlet UITableView *tblView;
        NSMutableArray *arrayCheckUnchek; // Will handle which button is selected or which is unselected
        NSMutableArray *cellDataArray; // this is your data array
    }
    
    @end
    

    Now in ViewController.m class –

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
        arrayCheckUnchek = [[NSMutableArray alloc]init];
        //Assign your cell data array 
        cellDataArray = [[NSMutableArray alloc]initWithObjects:@"cell-1",@"cell-2",@"cell-3",@"cell-4",@"cell-5", nil];
    
        // setting all unchecks initially
        for(int i=0; i<[cellDataArray count]; i++)
        {
            [arrayCheckUnchek addObject:@"Uncheck"];
        }
    
    }
    
    
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return [cellDataArray count];
    }
    
    -(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.textLabel.text = [cellDataArray objectAtIndex:indexPath.row];
    
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setFrame:CGRectMake(270.0, 7.0, 30.0, 30.0)];
    
        if([[arrayCheckUnchek objectAtIndex:indexPath.row] isEqualToString:@"Uncheck"])
        [button setImage:[UIImage imageNamed:@"uncheck_icon"] forState:UIControlStateNormal];
        else
        [button setImage:[UIImage imageNamed:@"check_icon"] forState:UIControlStateNormal];
    
        [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:button];
    
        return cell;
    }
    
    -(void)buttonClicked:(id)sender
    {
        //Getting the indexPath of cell of clicked button
    
        CGPoint touchPoint = [sender convertPoint:CGPointZero toView:tblView];
        NSIndexPath *indexPath = [tblView indexPathForRowAtPoint:touchPoint];
    
        // No need to use tag sender will keep the reference of clicked button
        UIButton *button = (UIButton *)sender;
    
        //Checking the condition button is checked or unchecked.
        //accordingly replace the array object and change the button image
        if([[arrayCheckUnchek objectAtIndex:indexPath.row] isEqualToString:@"Uncheck"])
        {
            [button setImage:[UIImage imageNamed:@"check_icon"] forState:UIControlStateNormal];
            [arrayCheckUnchek replaceObjectAtIndex:indexPath.row withObject:@"Check"];
        }
        else
        {
            [button setImage:[UIImage imageNamed:@"uncheck_icon"] forState:UIControlStateNormal];
            [arrayCheckUnchek replaceObjectAtIndex:indexPath.row withObject:@"Uncheck"];
        }
    }
    

    And finally it will look like –

    enter image description here

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

Sidebar

Related Questions

First of all, apologize because I have seen some posts about this, but I
I have seen some posts about navigation and breadcrumbs but did not find the
I have seen some posts regarding this topic and a few blogs, but none
So I have seen some other posts similar, but not quite answering what I
Quite some time i`ve learnt MVC. I have seen various techniques to post data
I have seen some related questions but none focusing on the specific problem I
i have seen some hand rolled solutions but does jquery out of the box
I have seen some of the other answers on this topic but dont really
All right, I've seen some posts asking almost the same thing but the points
I have seen some posts of the asp:menu and the browsers Chrome and Safari

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.