How to add a google instant search bar to ios application

1.1k views Asked by At

I want to add a google instant search bar in my iOS application like the one in iOS Safari and I couldn't find it anywhere. Can you guys help? Thanks in advance.

1

There are 1 answers

1
brush51 On

I assume that you are using UISearchBar.

You can use your code from

- (void) searchBarSearchButtonClicked:(UISearchBar *)theSearchBar

in method

- (void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText

Just keep in mind, that you dont need to resignFirstResponder in searchBar:textDidChange.

For example, in this methods can be:

NSError *error = nil;

// We use an NSPredicate combined with the fetchedResultsController to perform the search
if (self.mySearchBar.text !=nil)
{
    if ([searchCriteria isEqualToString:@"artist"])
    {
        NSPredicate *predicate =[NSPredicate predicateWithFormat:@"artist  contains[cd] %@", self.mySearchBar.text];
        [fetchedResultsController.fetchRequest setPredicate:predicate];
    }
}
else
{
    NSPredicate *predicate =[NSPredicate predicateWithFormat:@"All"];
    [fetchedResultsController.fetchRequest setPredicate:predicate];
}

if (![[self fetchedResultsController] performFetch:&error])
{
    // Handle error
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    exit(-1);  // Fail
}

// this array is just used to tell the table view how many rows to show
fetchedObjects = fetchedResultsController.fetchedObjects;

// dismiss the search keyboard
[mySearchBar resignFirstResponder];

// reload the table view
[myTableView reloadData];

}    

Feel free to +1 this answer, if that helps for someone like me, they come from google search results to this post :)

brush51