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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:54:44+00:00 2026-06-09T09:54:44+00:00

Currently I am coding the search capability of a UISearchBar using data from a

  • 0

Currently I am coding the search capability of a UISearchBar using data from a DB that’s displayed in a table. I figure out the search results and save them to NSMutableArray *searchResults. Here’s how that looks:

- (void) searchGrapesTableView {
    [searchResult removeAllObjects];
    numSearchWines=0;
    for (NSString *str in listOfWines)
    {
        NSRange titleResultsRange = [str rangeOfString:searchBar.text options:NSCaseInsensitiveSearch];
        if (titleResultsRange.length > 0) {
            [searchResult addObject:str];
            numSearchWines++;
        }
    }
}

listOfWines is also an NSMutableArray that contains a list of all the names that can be searched from. IDEALLY, I would like to determine the index of the object in listOfWines that has the matching value and add it to another NSMutableArray, so that way I can later access it really easily. For example, later on when I display the table cells using this search data, I have the following code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"wineCell"];
    //determine how many to add to get the grape ID
    NSInteger grapeID=0;
    for (int i=0; i<indexPath.section; i++) {
        grapeID += [self.tableView numberOfRowsInSection:i];
    }

    Wines *currentWine;
    if (isSearchOn) {
        NSString *cellValue = [searchResult objectAtIndex:(grapeID+indexPath.row)];
        NSInteger index = 0;
        index = [listOfWines indexOfObject:cellValue];
        currentWine = [allWines objectAtIndex:(index)];
    }

    else {
        currentWine = [allWines objectAtIndex:(grapeID+indexPath.row)];
    }

    cell.textLabel.text = currentWine.name;
    return cell;
}

Unfortunately this doesn’t work if there are duplicate entries in listOfWines (and subsequently searchResult). That’s why it would be so useful to also have their indexes in, for example, an NSMutableArray named searchResultID, so that I can do something like this:

NSInteger theResultID = [searchResultID objectAtIndex:(grapeID+indexPath.row)];
currentWine = [allWines objectAtIndex:theResultID];
  • 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-09T09:54:47+00:00Added an answer on June 9, 2026 at 9:54 am

    This sounds like a job for indexesOfObjectsPassingTest:. You should check it out in the NSArray docs. You use it something like this:

    NSIndexSet  *indxs = [allWines indexesOfObjectsPassingTest: ^BOOL(NSString *obj, NSUInteger idx, BOOL *stop) {
            return [obj isEqualToString:searchBar.text]];
        }];
    

    So this will loop through all the values in allWines (I’m assuming the objects are strings) and return the indexes of any that match the search string, giving you an index set with any indexes found.

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

Sidebar

Related Questions

I'm currently coding a simple search script in PHP that requires three variables from
I am currently coding setup.py using setuptools. And I want to copy the static
I'm currently trying to learn WinSock coding from http://johnnie.jerrata.com/winsocktutorial/ however when I compile my
I'm currently using a JavaScript coding style based on Douglas Crockford's Code Conventions for
I'm currently working on some coding for a hotel booking widget and am using
I'm coding Settlers of Catan for iOS and currently have my data tiles in
I've currently noticed that many people start using this model very often. Anyways, I
I have a form that searches a MySQL database using PHP. Currently, when a
Here is my code, from the search results page: {if $listing.SalaryType!=''&& $listing.Salary!=''}<dt>Salary:</dt> <dd>{$listing.Salary} {$listing.SalaryType}</dd>{/if}
I'm currently coding my own CMS and I'm at the point of the search.php

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.