2011-11-28 7 views

답변

2

나는 당신이 UISearchBar를 사용하고 있다고 가정합니다. textDidChange을 :

당신은 그냥 당신이 검색 창에 resignFirstResponder 할 필요가없는 것을 명심

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

방법

- (void) searchBarSearchButtonClicked:(UISearchBar *)theSearchBar 

에서 코드를 사용할 수 있습니다. 이 방법의 예를 들어

이 될 수있다 : 즉 나 같은 사람을 위해 도움이된다면

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

Google 검색 결과에 대해 Google과 인터페이스 할 수있는 API를 더 찾고있었습니다. –