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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:09:59+00:00 2026-05-27T15:09:59+00:00

I have a UISearhBarController in my app. It currently searches an online database, but

  • 0

I have a UISearhBarController in my app. It currently searches an online database, but I’m changing it to search a core data database instead. Its currently using this code:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText 
{
    if (self.billingSearchBar == searchBar) {
        [self.billingSearchController filterResultsUsingString:searchText];
    }
}

- (void)filterResultsUsingString:(NSString *)filterString 
{
    self.billingSearchText = filterString;
    NSArray *billing_codes = [self billingSearch:self.billingSearchText searchType:self.billingSearchCategory];
    self.displayedBillingSearch = billing_codes;
    self.billingSearch = billing_codes; 
    [self.tableView reloadData];
}

-(NSMutableArray*)billingSearch:(NSString*)searchString searchType:(NSString*)searchType
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/server/20111115/60b88126/billing_search/", [self getHost]]];

    ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
    [request setPostValue:searchString forKey:@"query"];
    [request setPostValue:searchType forKey:@"category"];

    [request startSynchronous];
    NSError *error = [request error];
    NSString *responseString;
    if (!error) {
        responseString = [request responseString];
    }

    NSMutableArray *search_results = [[NSMutableArray alloc] init];
    NSDictionary *responseDictionary = [responseString JSONValue];

    for (id key in [responseDictionary valueForKey:@"search_results"]) {
        [search_results addObject:key];
    }
    return search_results;  
}

So I have the database setup in core data already, I just need to hook up the search/NSFetchedResults controller to it. Any easy way to do so?

  • 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-27T15:10:00+00:00Added an answer on May 27, 2026 at 3:10 pm

    The cleanest way to do that is to use two NSFetchedResultsControllers and set the predicate on your “searching” NSFRC to be the searchText in the UISearchBar. After you decide which NSFRC to use, you just set your self.fetchedResultsController = “searching” NSFRC or the “default” NSFRC.

    You can also use the same NSFRC and change the predicate, but that is not the recommended way to do it.

    See comment below. If all that is changing is the predicate, one FRC is fine.

    Here is sample code to get this done:

    // First use the Searchbar delegate methods
    -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
    {   
        [self filterContentForSearchText:searchText];
    }
    
    -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
        [self filterContentForSearchText:searchBar.text];
        [searchBar resignFirstResponder];
    }
    
    // The method to change the predicate of the FRC
    - (void)filterContentForSearchText:(NSString*)searchText
    {
        NSString *query = searchText;
        if (query && query.length) {
            NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name contains[cd] %@ or department contains[cd] %@", query, query];
            [self.fetchedResultsController.fetchRequest setPredicate:predicate];
            [self.fetchedResultsController.fetchRequest setFetchLimit:100]; // Optional, but with large datasets - this helps speed lots
        }
    
        NSError *error = nil;
        if (![[self fetchedResultsController] performFetch:&error]) {
            // Handle error
            exit(-1);
        }
    
        [self.myTableView reloadData];
    }
    

    This should get ya started.

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

Sidebar

Related Questions

Have searched the database but need to specifically sum(of hours flown or days off)in
Have an issue with a Java Web App when using JSF + PrettyFaces to
Have done some working samples using Backbone Router, but is there a way to
have been playing with Cubepoints (wordpress plugin) and have installed the ranks module but
Have a singleton class for BNRItemStore, but when I tried to call it, I
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have converted devise new session from erb to Haml but doens't work, this is
have been trying couple of hours now to make my iphone app universal. The
Have some code: using (var ctx = new testDataContext()) { var options = new

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.