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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:15:32+00:00 2026-05-26T10:15:32+00:00

I am creating an application where the user can select multiple cells from a

  • 0

I am creating an application where the user can select multiple cells from a table, and each time a cell is selected, it is being added to an NSMutableArray. The table contains names of different countries. Once all the countries are selected, how do I search for which countries are selected? For example, how do I check if the user selected United States for example?

I have this in my didSelectRow for my table:

if ([selectedCell accessoryType] == UITableViewCellAccessoryNone) {
        [selectedCell setAccessoryType:UITableViewCellAccessoryCheckmark];
        [listofCountriesselected addObject:[NSNumber numberWithInt:indexPath.row]];

    } 
    else {
        [selectedCell setAccessoryType:UITableViewCellAccessoryNone];
        [listofCountriesselected removeObject:[NSNumber numberWithInt:indexPath.row]];

    }
  • 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-26T10:15:33+00:00Added an answer on May 26, 2026 at 10:15 am

    You can add the countries to the NSMutableArray and check containsObject. In this case, I’m adding a string – you can add via some country identifier but you need to check by the same country identifier (whatever you choose). Row number is not a good identifier – it’s not stable.

    NSMutableArray *list = [[NSMutableArray alloc] init];
    [list addObject:@"US"];
    [list addObject:@"CN"];
    NSLog(@"usa? %d", (int)[list containsObject:@"US"]);
    

    An even faster way to check if a country has been selected would be to add the country to an NSMutableSet when selected.

    An NSMutableSet is a hash set so look ups are very fast.

    NSMutableSet *lookup = [[NSMutableSet alloc] init];
    [lookup addObject:@"US"];
    [lookup addObject:@"CN"];
    
    NSLog(@"usa? %d", (int)[lookup containsObject:@"US"]);
    

    Both output 1.

    The key difference is the NSMutableArray is an order list of items – a list. The NSMutableSet is optimized for contains – just a set. For example, if you wanted to not only track what’s selected but the order they selected them in, then you need a mutable array. It’s also not uncommon for apps to contain aggregate data structures to answer ordering and contains type questions.

    BTW, here’s how you can get all the ISO country codes

    NSArray *countryCodes = [NSLocale ISOCountryCodes];
    for (NSString *cc in countryCodes)
    {
        NSLog(@"cc: %@", cc);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an alarm application. In my application, the user can select the days
I'm creating a Java application where the user can search through a list of
I'm creating a multiform application in c#. I'm storing the values from the user
I am creating a bulletin board application. Each bulletin can be liked or disliked
I'm creating a content management system where a user can select a css file
I am creating a java application that connects to multiple databases. A user will
I'm creating a web application for work where the user has to enter the
I'm creating a web application on Google AppEngine where I want the user to
When creating a web application, and lets say you have a User object denoting
When I'm creating a user for my web application, an SMTP email (using ASP.NET's

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.