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

  • Home
  • SEARCH
  • 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 7786151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:22:12+00:00 2026-06-01T20:22:12+00:00

I am thinking of using a for loop, but was wondering if there was

  • 0

I am thinking of using a for loop, but was wondering if there was any built in way to accomplish this. Basically in one view I have a table view with a list of objects, the user can click as many as they want, “checking” them. When they go to the next string I want to populate another table view with the selected names.

Here is my selection method:

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


    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

    if (cell.accessoryType == UITableViewCellAccessoryNone)
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    else
        cell.accessoryType = UITableViewCellAccessoryNone;

    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

I’m thinking of writing a method that contains a for loop that goes through each value in the array that the table view is pulled from and adds only those with the correct accessory type to a new array. Any ideas?

  • 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-01T20:22:13+00:00Added an answer on June 1, 2026 at 8:22 pm

    It would be more MVC to back your selections with an NSMutableIndexSet. Otherwise, what happens if the user selects a cell, but then scrolls the cell out of the frame and it gets dequeued?

    Declare a propery in your interface:

    @property (strong) NSMutableIndexSet* selected;
    

    Instantiate it in viewDidLoad or somewhere similar
    Then modify it in your delegate method:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    
        if (![self.selected containsIndex:indexPath.row])
        {
            [self.selected addIndex:indexPath.row];
        }
        else
        {
            [self.selected removeIndex:indexPath.row];
        }
    
        [tableView deselectRowAtIndexPath:indexPath animated:NO];
    }
    

    In your cellForRowAtIndexPath: method, decide whether to show a checkmark or not:

    cell.accessoryType = [self.selected containsIndex:indexPath.row] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
    

    Now when you want the selected objects, just

    return [self.myObjects objectsAtIndexes:self.selected];
    

    Note: when I first posted this, it was really untested. I’ve since made several changes. For example, you want to set accessoryType in the cellForRowAtIndexPath: method ONLY

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

Sidebar

Related Questions

I know that using .net VSTO there is no way to do this. but
I'm using Thinking Sphinx for full-text search, following this video . I'd like to
I am thinking of using a PHP framework called CodeIgniter . One of the
I'm thinking about using log4net in a MOSS(SharePoint) 2007 project, but I need to
I was thinking of using a Double as the key to a HashMap but
I'm sure this is not a very pythonic situation. But I'm not actually using
I am wondering if there are any additional optimizations I can implement to improve
I am trying to print out this pattern using a for loop in Java
I am using asp.net mvc 3 and thinking what the best way to handle
I have this simple while loop which retrieves data from a mysql query and

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.