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.
Asked
Active
Viewed 1,138 times
1 Answers
2
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

brush51
- 5,691
- 6
- 39
- 73
-
I was more looking for an api to interface with google for their search results – Jordan Medlock Mar 02 '12 at 01:51