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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:10:49+00:00 2026-06-17T17:10:49+00:00

I have a tableview that filters based on a search bar. This works well

  • 0

I have a tableview that filters based on a search bar. This works well as long as the search begins with the same characters as the cell text.

I would like to be able to search any part of the cell text, even in the middle. For example. If the cell text is “Jon Bon Jovi” I would like it to still come up if the user types “Bon Jovi” or even just “Jovi” into the search bar.

My current code is below:

for (NSDictionary *item in listItems)
{

    if ([scope isEqualToString:@"All"] || [[item objectForKey:@"type"]  
    isEqualToString:scope] || scope == nil)
    {
        NSComparisonResult result = [[item objectForKey:@"name"] 
        compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) 
        range:NSMakeRange(0, [searchText length])];

        if (result == NSOrderedSame)
        {
            [filteredListItems addObject:item];
        }
    }
}

Any help would be awesome. Thank you all!

  • 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-17T17:10:50+00:00Added an answer on June 17, 2026 at 5:10 pm

    Instead of using -compare:options:range: (which just sorts your search string relative to your item’s name), consider looking at -rangeOfString:options: – that will actually search the entire item name for your search string. You would replace the inner body of your if statement with something like:

    NSStringCompareOptions opts = (NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch);
    NSRange resultRange = [[item objectForKey:@"name"] rangeOfString:searchText
                                                             options:opts];
    if (resultRange.location != NSNotFound) {
        [filteredListItems addObject:item];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tableView that's loosely based on the DetailViewController in ye olde SQLiteBooks.
I have a tableview, with a search bar. The table is loaded with 3700
i have one tableview that have custom cells and one cell contains uiimageview,uilabels .
I have a tableView that present a list of Books, each of the table
I have a tableview that occupies only the bottom third of my view. I
I have created an tableview that shows RSSS. I check for internet connection then
I have a Tableview on AppDelegate That calls a SecondView (dvController) when DidSelectRowAtIndexPath using:
I have a controller that contains a tableView that spawns another controller modally to
I have 5 cells in a tableview that are all custom. Meaning, I've created
I have a TableView with 10 sections that are loaded from a plist file

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.