我目前用于创建UISearchBar的这段代码(改编自之前的stackoverflow示例):
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
[searchBar sizeToFit];
//searchBar.delegate = self;
searchBar.placeholder = @"Search messages, listeners or stations";
self.tableView.tableHeaderView = searchBar;
UISearchDisplayController *searchDC = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
// The above assigns self.searchDisplayController, but without retaining.
// Force the read-only property to be set and retained.
[self performSelector:@selector(setSearchDisplayController:) withObject:searchDC];
//searchDC.delegate = self;
//searchDC.searchResultsDataSource = self;
//searchDC.searchResultsDelegate = self;
[searchBar release];
[searchDC release];
我需要在工具栏的底部添加3个范围按钮:“主题”,“消息”,“工作站”并默认选择第一个。有人可以告诉我怎么做吗?
答案 0 :(得分:16)
哦..没关系..发现它..
searchBar.showsScopeBar = YES;
searchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"Flags", @"Listeners", @"Stations", nil];