2
我想在我的iOS应用程序中添加一个谷歌即时搜索栏,就像iOS Safari中的一个,我无法在任何地方找到它。你们能帮忙吗? 在此先感谢。如何添加谷歌即时搜索栏到iOS应用程序
我想在我的iOS应用程序中添加一个谷歌即时搜索栏,就像iOS Safari中的一个,我无法在任何地方找到它。你们能帮忙吗? 在此先感谢。如何添加谷歌即时搜索栏到iOS应用程序
我假定你正在使用UISearchBar。
您可以使用代码
- (void) searchBarSearchButtonClicked:(UISearchBar *)theSearchBar
的方法
- (void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
只要记住,你不需要在搜索栏,以resignFirstResponder:textDidChange。
例如,在这种方法可能是:
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];
}
随意+1这个答案,如果这能帮助像我,他们来自谷歌搜索结果中这个帖子:)
brush51
我更寻找一个API接口与谷歌的搜索结果 –