2011-11-28 39 views

回答

2

我假定你正在使用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

+0

我更寻找一个API接口与谷歌的搜索结果 –

相关问题