2012-10-30 17 views
5

Ho implementato un UISearchDisplayController in UITableViewController. La ricerca funziona, ma UISearhDisplayController crea una nuova tabellaView con una cella standard e my TableView utilizza una cella personalizzata. Un altro problema è che io uso un segue:UISearchDisplayController e cella personalizzata

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 

e le cellule in searchResultsTableView non attivano il Segue ..

Come per visualizzare i risultati di ricerca con cellule costume e Segue lavorare?

Questo è il codice:

... 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
if (tableView == self.searchDisplayController.searchResultsTableView){ 
return [nameFilteredObj count]; 
} else { 
return [sortedObj count]; 
}} 

- (CustomCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"customCell"; 

CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) { 
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 
if (tableView == self.searchDisplayController.searchResultsTableView) 
{ 
cell.textLabel.text = [[sortedObj objectAtIndex:indexPath.row] valueForKey:@"Name"]; 
} else { 
cell.nameLabel.text = [[sortedObj objectAtIndex:indexPath.row] valueForKey:@"Name"]; 
cell.countryLabel.text = [[sortedObj objectAtIndex:indexPath.row] valueForKey:@"Country"]; 
cell.bottleImageView.image = [UIImage imageNamed:[[sortedObj objectAtIndex:indexPath.row] valueForKey:@"Image"]]; 
} 
return cell; 
} 

//The codes for filtering the results and update of searchResultsTableView (not necessary for this question I think): 

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope 
{ 
[nameFilteredObj removeAllObjects]; 

for(NSDictionary *obj in sortedObj) 
{ 
NSString *objName = [obj objectForKey:@"Name"]; 
NSRange range = [objName rangeOfString:searchText options:NSCaseInsensitiveSearch]; 
if (range.location != NSNotFound) { 
    [nameFilteredObj addObject:obj]; 
}}} 

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString 
{ 
[self filterContentForSearchText:searchString scope: 
[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]]; 
return YES;} 

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption 
{ 
[self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope: 
[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]]; 
return NO;} 
... 

sto usando Storyboard come interfaccia.

+1

è stata impostata su 'self.searchDislpayController.searchResultsDataSource' a' self'? E il 'searchResultsDelegate'? – rmaddy

+0

Posso mostrarmi per favore? – ingenspor

+1

'self.searchDisplayController.searchResultsDataSource = self'. Fatelo dove create il controller di ricerca. – rmaddy

risposta

-8

In realtà molto facile da fare, ma ho trovato molte complicate soluzioni semiadavorative in arrivo. Utilizzare questo pezzo semplice e SearchResultsTableView è andato:

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString 
{ 
... 
self.searchDisplayController.searchResultsTableView.hidden=YES; 
return YES; 
} 
+2

Come è questa la soluzione? Tutto quello che stai facendo è nascondere la vista tabella che dovrebbe mostrare i risultati filtrati e mostrare invece la vista tabella non filtrata. – ShatyUT

+1

cazzuto, amico .... – saiday

Problemi correlati