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
filterContentForSearchText가 전화를 받았는지 확인 했습니까? –
이 메소드를 작성한 UISearchBar가 사용되었습니다. - (void) searchBar : (UISearchBar *) theSearchBar textDidChange : (NSString *) searchText –