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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:31:17+00:00 2026-05-22T15:31:17+00:00

I have a UITableView populated with 27 rows. I am trying to change the

  • 0

I have a UITableView populated with 27 rows. I am trying to change the accessoryType of the selected cell. I do that in the didSelectRowAtIndexPath: delegate method.

The problem I am facing is that, when selecting a row and changing the accessoryType of the cell, the eleventh row from that row also gets modified.

I have tried printing the [indexPath row] value, but it’s showing only the row that was selected and not another one.

I am really puzzled by such stuff; please help me out.

ADDED THE CODE cellForRowAtIndexPath method

UITableViewCell *cell;
if ([indexPath row] == 0) {
    cell = [tableView dequeueReusableCellWithIdentifier:@"acell"];
}
else {
    cell = [tableView dequeueReusableCellWithIdentifier:@"bcell"];
}

cell.selectionStyle = UITableViewCellSelectionStyleNone;

if (cell == nil && [indexPath row] != 0) {
    cell = [[[UITableViewCell alloc] initWithStyle:
             UITableViewCellStyleSubtitle reuseIdentifier:@"bcell"] autorelease];
}
else if(cell == nil && [indexPath row] == 0){
    cell = [[[UITableViewCell alloc] initWithStyle:
             UITableViewCellStyleSubtitle reuseIdentifier:@"acell"] autorelease];
}

if ([cell.contentView subviews]){
    for (UIView *subview in [cell.contentView subviews]) {
        [subview removeFromSuperview];
    }
}
if ([indexPath row] == 0) {
    cell.textLabel.text = @"Select All";
    cell.textLabel.font = [UIFont boldSystemFontOfSize:13.0f];
}
else {
    cell.textLabel.text = @"Some Text Here"
    cell.detailTextLabel.text = @"Another piece of text here"   
}
return cell;

I am doing %10 because the behaviour is repeating after 11th row, hence trying to create new object for every 11th row.

My didSelectRowAtIndexPath methos code is

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
    if ([indexPath row] != 0) {
        NSIndexPath *tempIndex = [NSIndexPath indexPathForRow:0 inSection:0];
        UITableViewCell *tempCell = [tableView cellForRowAtIndexPath:tempIndex];
        tempCell.accessoryType = UITableViewCellAccessoryNone;
    }
    cell.accessoryType = UITableViewCellAccessoryNone;
}
else{
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
if ([indexPath row] == 0) {
    for (int i = 0; i < [dataSource count]; i++) {
        NSIndexPath *tempIndex = [NSIndexPath indexPathForRow:i+1 inSection:0];
        UITableViewCell *tempCell = [tableView cellForRowAtIndexPath:tempIndex];
        if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
            tempCell.accessoryType = UITableViewCellAccessoryCheckmark;
        }
        else{
            tempCell.accessoryType = UITableViewCellAccessoryNone;
        }
    }
}

Please help me in multiple selection or anyother way to solve the problem of multiple selection.

Thanks in advance!!

  • 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-22T15:31:17+00:00Added an answer on May 22, 2026 at 3:31 pm

    Here’s one way to do it:

    - (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] autorelease];        
        }
    
        [cell.textLabel setText:[NSString stringWithFormat:@"Row %d", indexPath.row]];
    
        NSIndexPath* selection = [tableView indexPathForSelectedRow];
        if (selection && selection.row == indexPath.row) {
            cell.accessoryType = UITableViewCellAccessoryCheckmark; 
        } else {
            cell.accessoryType = UITableViewCellAccessoryNone;  
        }
    
        // Configure the cell.
        return cell;
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
    }
    
    - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
    }
    

    Remember every cell in the table view is actually the same object being re-used. If you don’t set the accessory type every time cellForRowAtIndexPath is called, when new cells scroll onto the screen they’re going to all have the same accessory.

    Multiple Select

    For multiple selection it’s a bit more complicated.

    Your first option: Undocumented API

    Note that this only works when the table’s in editing mode. Set each cell’s editing style to the undocumented UITableViewCellEditingStyleMultiSelect. Once you do that, you can get the table view’s selection via an undocumented member of UITableView: indexPathsForSelectedRows. That should return an array of the selected cells.

    You can expose this bit of functionality by putting this in a header:

    enum {
        UITableViewCellEditingStyleMultiSelect = 3,
    };
    
    @interface UITableView (undocumented)
    - (NSArray *)indexPathsForSelectedRows;
    @end
    

    Then set the editing style for each cell like so:

    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
        return UITableViewCellEditingStyleMultiSelect;
    }
    

    When the table is in editing mode you’ll see the multi-select controls on your cells.

    To look through other undocumented API, you can use the nm command line utility like this:

    nm /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/System/Library/Frameworks/UIKit.framework/UIKit
    

    Your second option: Manage the selection yourself

    Have your UITableView subclass contain an array that indicates which cells are selected. Then in cellForRowAtIndexPath, configure the cell’s appearance using that array. Your didSelectRowAtIndexPath method should then look something like this:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if ([tableView indexPathIsSelected:indexPath]) {
            [tableView removeIndexPathFromSelection:indexPath];
        } else {
            [tableView addIndexPathToSelection:indexPath];
        }
        // Update the cell's appearance somewhere here
        [tableView deselectRowAtIndexPath:indexPath animated:NO];
    }
    

    This assumes you create indexPathIsSelected, removeIndexPathFromSelection, and addIndexPathToSelection methods in your UITableView subclass. These methods should do exactly what their names imply: Add, remove, and check for index paths in an array. You wouldn’t need a didDeselectRowAtIndexPath implementation if you go with this option.

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

Sidebar

Related Questions

I have a UITableView that gets populated from CoreData via a controller that implements
I have a UITableView that is populated with cells of a variable height. I
I have a uitableview that is populated from a sqlite query. I want to
I'm new to Objective-C and I have a UITableView that is populated by an
I have a UITableView that is populated with custom cells (inherited from UITableViewCell ),
I have an UITableview which has a description cell populated by an NSString ,
I have a UITableView that gets populated my a NSMutableArray. This is how I
I have a UITableView that gets populated via CoreData , and have just noticed
I have the following method that should populate the cells of my UITableView with
I have a UITableView populated with a bunch of music players that I've made

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.