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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:54:24+00:00 2026-05-31T19:54:24+00:00

I am trying to get the ‘Search Bar and Display Controller’ functionality to work

  • 0

I am trying to get the ‘Search Bar and Display Controller’ functionality to work in an iOS app. I am able to NSLog in repsonse to a search query and hardcode in a new array but am unable to get the table view to repopulate. I have the following for in response to a user submit on the search button:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
  NSLog(@"You clicked the search bar");
  NSMutableArray *filteredResults=[[NSMutableArray alloc] init];

  Person *filteredPerson=[[Person alloc] init];
  filteredPerson.firstName=@"Josie - here i am";
  [filteredResults addObject:filteredPerson];
  _objects=filteredResults;
  self.tableView.dataSource = _objects;
  [self.tableView reloadData];
}

Any ideas on making this repopulate would be appreciated.

thx

edit #1
It looks like this is populating the _objects NSMutableArray:

- (void)insertNewObject:(id)sender
{
    if (!_objects) {
        _objects = [[NSMutableArray alloc] init];
    }
    [_objects insertObject:[NSDate date] atIndex:0];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}

Should I just create a new _objects and use insertNewObject rather than the addObject code I have above? Would this bypass the need to deal with the dataSource property of the table view?

edit 2
per @ian

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    /*
    NSDate *object = [_objects objectAtIndex:indexPath.row];
    cell.textLabel.text = [object description];
    */

    Person *rowPerson = [_objects objectAtIndex:indexPath.row];
    cell.textLabel.text = [rowPerson firstName];

    return cell;
}

thx

  • 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-31T19:54:26+00:00Added an answer on May 31, 2026 at 7:54 pm

    I have a UITableView that uses an NSMutableArray to hold the data. Here’s how it works: set the UISearchDisplayController’s delegate to your TableView controller, and when the UITableViewDelegate methods are called (numberOfRows, numberOfSections, cellForRowAtIndexPath, etc) you can do the following to serve up the search data when appropriate:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        NSInteger numberOfRows = 0;
    
        if (tableView == self.searchDisplayController.searchResultsTableView)
        {
            //This is your search table --- use the filteredListContent (this is the NSMutableArray)
            numberOfRows = [filteredListContent count];
        }
        else
        {
            //Serve up data for your regular UITableView here.
        }
    
        return numberOfRows;
    }
    

    You should take a look at the UISearchDisplayDelegate documentation. You can use these methods to update your filteredListContent array, as follows:

    #pragma mark -
    #pragma mark Content Filtering
    
    - (void)filterContentForSearchText:(NSString*)searchText
    {   
        //In this method, you'll want to update your filteredListContent array using the string of text that the user has typed in. For example, you could do something like this (it all depends on how you're storing and retrieving the data):
    
        NSPredicate *notePredicate = [NSPredicate predicateWithFormat:@"text contains[cd] %@", searchText];
        self.filteredListContent = [[mainDataArray filteredArrayUsingPredicate:notePredicate] mutableCopy];
        }
    
    
    #pragma mark UISearchDisplayController Delegate Methods
    - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
    {
        [self filterContentForSearchText:searchString];
    
        // Return YES to cause the search result table view to be reloaded.
        return YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying get Struts 2 and Tiles to work and I am using
Trying to get this to work, with no luck: [DataMember] public Type ParameterType {
I've been at this for 12+ exhausting hours trying get it to work on
Trying to get the home page to display a 4 column grid for the
I'm trying get LocalConnection to work between two swf's placed within two different IFRAMES.
I am trying get Javascript popup calendar control to work which doesnt work. I
in my app i am trying to get an xml file from an URL.
Trying to get tag-it to work with an ajax call. Everything works so far.
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I am trying get all html links within a string and replace them using

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.