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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:58:23+00:00 2026-06-08T13:58:23+00:00

I have 30 rows in uitable view and I am attempting to select multiple

  • 0

I have 30 rows in uitable view and I am attempting to select multiple rows and set them to checked.

Whenever I select one row, automatically another row is selected and checked with the desired row.

Also when I scroll the tableview it changes selection automatically.

I had used this code with less number of rows (8) and it worked perfectly. For more than 12 rows it gives the problem I have described.

If you can suggest any other code/tutorial to make it work is also okay.

I am new to xcode, any help is much appreciated. Thank you.

Here is my code:

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [listOfItems count];
}

// Customize the appearance of table view cells.
- (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];
}

// Configure the cell...
NSString *cellValue = [listOfItems objectAtIndex:indexPath.row];
cell.text = cellValue;

return cell;
}

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];

if ([selectedCell accessoryType] == UITableViewCellAccessoryNone) {

    if(count < 3)
    {

        [selectedCell setAccessoryType:UITableViewCellAccessoryCheckmark];
        [selectedIndexes addObject:[NSNumber numberWithInt:indexPath.row]];
        count++;
    }

    NSLog(@"Count: %d", count);
    NSLog(@"Items I selected @ %d:", indexPath.row);
    NSLog(@"Items I selected: %@", selectedIndexes);
} 

else {

    [selectedCell setAccessoryType:UITableViewCellAccessoryNone];
    [selectedIndexes removeObject:[NSNumber numberWithInt:indexPath.row]];
    count --;
    NSLog(@"Items I de-selected @ %d:", indexPath.row);

}

[tableView deselectRowAtIndexPath:indexPath animated:NO];

NSMutableString *resultlearning = [[NSMutableString alloc]init];
for (int i = 0; i < [listOfItems count]; i++) {
    NSIndexPath *path = [NSIndexPath indexPathForRow:i inSection:0];
    //[tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
    if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
        [resultlearning appendFormat:@"%@, ",cell.textLabel.text];
    }
}
if (resultlearning.length > 2) {
    [resultlearning replaceCharactersInRange:NSMakeRange(resultlearning.length-1, 1) withString:@""];
}
NSLog(@"Result: %@",resultlearning);
}
  • 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-08T13:58:25+00:00Added an answer on June 8, 2026 at 1:58 pm

    Add one mutablearray in .h file.Here add as many object to array as your tableDataSourc array has. Now my intension is that if it contains 0 then that cell is not selected or it contains 1 then that cell is selected

    Now do this as u have selectedIndexes array so need of another mutablearray :

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    // Return the number of rows in the section.
    for(int i = 0;i<[listOfItems count];i++)
    {
    [selectedIndexes addObject:@"0"];
    }
       return [listOfItems count]
     }
    
    
     - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
     UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
    
     if ([selectedCell accessoryType] == UITableViewCellAccessoryNone) {
    
         [selectedCell setAccessoryType:UITableViewCellAccessoryCheckmark];
         [selectedIndexes replaceObjectAtIndex:indexPath.row withObject:@"1"];
    }
    else
    {          
    selectedCell.accessoryType = UITableViewCellAccessoryNone;
    [selectedIndexes replaceObjectAtIndex:indexPath.row withObject:@"0"];
    }
    

    Now selectedIndexes has object with 1 value means that value is selected in listOfItems

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

Sidebar

Related Questions

I am making a simple timer app. I have a uitable with multiple rows.
I have a UITableView for different datas. When the user select one row, then
I have a project: first view is uitableview, when you select row uinavigationcontroller pushes
I have a UITableView with 3 empty rows. The user can select which text
I quite often have rows of code like the following: UPDATE my_table SET name
In my iphone application i have added the Uitable view. While launching the application
I have a standard UITable. When the user scrolls through the rows and then
Initially i have a table view with only one add button. when user press
I would like to select multiple rows in a UITableview just like Apple does
I'm attempting to have a UITableView that I can dynamically add and remove rows

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.