-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