Wenn mein Benutzer ein Element in meiner UISearchBar durchsucht, werden die Ergebnisse angezeigt, wenn das in die Leiste eingegebene vollständige Wort mit einem der Ergebnisse übereinstimmt. Zum Beispiel Wenn "Panda" eingegeben wird, erscheint Panda in der Tabelle Ergebnisse anzeigen. Wenn jedoch "Pan" eingegeben wird, werden keine Ergebnisse angezeigt. Wie kann ich meinen Suchergebnisfilter so arbeiten lassen, wie der Benutzer tippt? Panda, auch wenn nur "pan" werden sollte, wird angezeigt eingegebenUISearchBar zeigt keine Ergebnisse bei der Texteingabe
Mein Filter Code sieht derzeit wie folgt aus:.
.m
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"SELF contains[cd] %@",
searchText];
searchResults = [self.neighbourData filteredArrayUsingPredicate:resultPredicate];
}
/*
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
return YES;
} */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
return [searchResults count];
} else {
return [self.neighbourData count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *NetworkTableIdentifier = @"sidebarCell";
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
sidebarCell *cell = (sidebarCell *)[tableView dequeueReusableCellWithIdentifier:NetworkTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"sidebarCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
NSDictionary *userName = [searchResults objectAtIndex:indexPath.row];
[[cell username] setText:[userName objectForKey:@"first name"]];
NSDictionary *userlast = [searchResults objectAtIndex:indexPath.row];
[[cell lastName] setText:[userlast objectForKey:@"last name"]];
NSDictionary *userBio = [searchResults objectAtIndex:indexPath.row];
[[cell userDescription] setText:[userBio objectForKey:@"userbio"]];
NSString *profilePath = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"photo_path"];
[cell.usermini sd_setImageWithURL:[NSURL URLWithString:profilePath]];
NSLog(@"This is profilePath %@",profilePath);
} else {
NSDictionary *userName = [self.neighbourData objectAtIndex:indexPath.row];
[[cell username] setText:[userName objectForKey:@"first name"]];
NSDictionary *userlast = [self.neighbourData objectAtIndex:indexPath.row];
[[cell lastName] setText:[userlast objectForKey:@"last name"]];
NSDictionary *userBio = [self.neighbourData objectAtIndex:indexPath.row];
[[cell userDescription] setText:[userBio objectForKey:@"userbio"]];
NSString *profilePath = [[self.neighbourData objectAtIndex:indexPath.row] objectForKey:@"photo_path"];
[cell.usermini sd_setImageWithURL:[NSURL URLWithString:profilePath]];
NSLog(@"This is profilePath %@",profilePath);
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 115;
}
neighbourData Log:
[12663:3559832] This is the neighbourdata (
{
address = "1144 fake street";
city = Las Vegas;
"first name" = Panda;
"last name" = Zoo;
"photo_path" = "none";
}
Das verursacht den folgenden SIGABRT-Fehler in dem Moment, in dem ich in der Suchleiste tippe: 'Die Format-Zeichenfolge kann nicht analysiert werden' Vorname enthält [cd]% @ "' – Brittany
Der Raum ist definitiv der Grund für den Absturz - gibt es einen Weg zu suche dieses Feld, ohne den Platz zu entfernen? Zu diesem Zeitpunkt ist es zu spät für mich, den Feldnamen zu ändern:/lol help! – Brittany
einmal mit dem aktualisierten Code versuchen – raki