0
Я новичок в разработке iOS и пытаюсь получить справку по результатам поиска. Все работает нормально, но когда я искать слово, он не показывает результат, так я буду над спасибо за вашу помощь .. Вот код ..Не удалось показать результаты UISearchBar
- (void)viewDidLoad
{
[super viewDidLoad];
mytableview.delegate = self;
mytableview.dataSource = self;
SearchBar.delegate = self;
titleArray = [[NSMutableArray alloc] initWithObjects:@"Arora town",@"Domino pizza ",@"thai hunt",nil];
subtitleArray = [[NSMutableArray alloc] initWithObjects:@"wX<w (rHR< cg)",@"o;vDRuwkR(vXw>csK;cHed;o;wkRtd.tCd)<*kRuhRto; (vXw>urXur.tylR)<o;vDRxl.",nil];
}
здесь cellForRowAtIndexPath
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *cellidentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellidentifier forIndexPath:indexPath];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
cell.textLabel.text = [self.searchResults objectAtIndex:indexPath.row];
}
else
{
cell.textLabel.text = [titleArray objectAtIndex:indexPath.row];
}
return cell;
}
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", searchText];
self.searchResults = [self.array filteredArrayUsingPredicate:predicate];
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
return YES;
}
Где находится 'self.array'? – Paulw11
проверили ли вы свой фильтр? Контент для поискового запроса получает вызов или нет? –
Вы используете UISearchBar, где вы написали этот метод - (void) searchBar: (UISearchBar *) theSearchBar textDidChange: (NSString *) searchText –