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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:19:02+00:00 2026-06-13T12:19:02+00:00

I implemented a Search Bar in a Xcode project to filter Core Data records.

  • 0

I implemented a Search Bar in a Xcode project to filter Core Data records. The problem is that the Seach seams to work (the search array is populated correctly, the number of rows of the tableview is shown correctly) but the Cell is empty.
Here is my code:

h file:

#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>

@interface iDataTable : UITableViewController <UISearchBarDelegate, UISearchDisplayDelegate> {
int nonume;
NSString *nume;
NSArray *arrTitle;
}
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain) NSString *nume;
@property (nonatomic) int nonume;
@property (nonatomic, retain) NSMutableArray *arrSearchRes;

@end

m file:

#import "iDataTable.h"
#import "AppDelegate.h"

@interface iDataTable ()

@end

@implementation iDataTable
@synthesize fetchedResultsController = __fetchedResultsController;
@synthesize managedObjectContext = __managedObjectContext;
@synthesize nume, nonume;
@synthesize arrSearchRes;


- (void)viewDidLoad{
[super viewDidLoad];


self.arrSearchRes = [NSMutableArray arrayWithCapacity:[[self.fetchedResultsController fetchedObjects] count]];

AppDelegate *appDelegate = 
[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = 
[appDelegate managedObjectContext];
NSEntityDescription *entityDesc = 
[NSEntityDescription entityForName:nume                   ///// language
            inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];


NSPredicate *pred = 
[NSPredicate predicateWithFormat:@"(nume != '')"];

request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"data" ascending:NO]];

[request setPredicate:pred];
NSError *error;
arrTitle = [context executeFetchRequest:request 
                                  error:&error];

[self.tableView reloadData];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if (tableView == self.searchDisplayController.searchResultsTableView) {
    return [self.arrSearchRes count];
}
else {
    return [arrTitle count];
             }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell != nil)
{

NSManagedObject* matches = nil;

     if (tableView == self.searchDisplayController.searchResultsTableView) {
        matches = [arrSearchRes objectAtIndex:indexPath.row];  // get search data
    }
    else {
        matches = [arrTitle objectAtIndex:indexPath.row];  // get general data            
    }

UILabel *cellLabel = (UILabel *)[cell viewWithTag:1];
[cellLabel setText:[matches valueForKey:@"nume"]];


}
else {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

return cell;
}


-(void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope {

AppDelegate *appDelegate = 
[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = 
[appDelegate managedObjectContext];
NSEntityDescription *entityDesc = 
[NSEntityDescription entityForName:nume                   ///// language
            inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];


NSPredicate *pred = 
[NSPredicate predicateWithFormat:@"(nume != %@)", searchText];

request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"data" ascending:NO]];

[self.arrSearchRes removeAllObjects];

[request setPredicate:pred];
NSError *error;

NSArray *arr = [context executeFetchRequest:request error:&error];

self.arrSearchRes = [[NSMutableArray alloc] initWithArray:arr];

NSLog(@"%@, %@", arrSearchRes, searchText); // ok - arrSearchRes looks ok

}


-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
[self filterContentForSearchText:searchString scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];

return YES;
}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption {
[self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];

return YES;
}

Thank you!

  • 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-13T12:19:02+00:00Added an answer on June 13, 2026 at 12:19 pm

    This worked for me:

    [self.searchDisplayController.searchResultsTableView reloadData];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've implemented this search algorithm for an ordered array of integers. It works fine
I have implemented a UISearchDisplayController that allows users to search a table. Currently the
I have implemented the search bar in my app and it´s working fine, but
I have implemented a UITableView with search bar (and search display) - all works
I want to implement search bar in my application which will filter list view
I have created a search bar on GAE similar to facebook that shows you
I'm currently having the following issue in my project: I'm using Core Data to
I'm trying to implement search in my app. There are two Core Data entities,
I have implemented an autocomplete / instant search on a mobile application that I
In my website I have implemented search feature using full-text search. It works fine

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.