-1
我会通过下面的教程enter link description here需要了解搜索栏
目标C代码和跨越这个代码难倒我它是如何工作的传来:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
// find all the words wich begin with the letter:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", searchText];
// NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"contains[c] %@", searchText];
self.searchResults = [self.array filteredArrayUsingPredicate:predicate];
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
// update the tableview
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
return YES;
}
我不部分理解是:
scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
这是我的理解,我试图研究它,我知道范围的一个参数。但我现在需要一些解释这个作品。
嗯,你不能孤立地说。你在引用一行。该行是:[self filterContentForSearchText:searchString scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];'你不能孤立地拿一块,并询问它;它本身没有意义。你的问题就像问:“嗨,你好吗?” – matt