如何将Searchbar值和Scope Bar Value添加到变量中 所以我可以将它作为GET值发送到REST API,如
SEARCHTERM rateType
我有以下代码。
- (IBAction)showSearchOptions:(id)sender {
if(toggle == 0){
[self.searchBar sizeToFit];
self.searchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"High Rate", @"Low Rate", nil];
self.searchBar.showsScopeBar = YES;
[self.searchBar sizeToFit];
toggle = 1;
} else {
self.searchBar.scopeButtonTitles = nil;
[self.searchBar sizeToFit];
toggle = 0;
}
}
答案 0 :(得分:0)
对此的答案如下:如果整数声明正确,请你纠正吗?基于编码标准。这有效,但我希望永远变得更好。谢谢。我看到了文档
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
NSString *searchTerm = searchBar.text;
int rateLevel = searchBar.selectedScopeButtonIndex;
NSString *rateString = [NSString stringWithFormat:@" Your Search Term is '%@' and Your Rate Type is '%d'", searchTerm, rateLevel];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"hey!"
message:rateString
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Try Again",nil];
[alert show];
}
答案 1 :(得分:0)
也许您需要self.searchbar.text
这样的内容,而且通常是NSPredicate
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
NSPredicate *predi = [NSPredicate predicateWithFormat:@"tags CONTAINS[c] %@", self.searchBar.text];
}