iPhone Objective-C programmatically adding scope buttons to a UISearchBar
I currently this piece of code for creating a UISearchBar (adapted from a previous stackoverflow example):
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.
// Fo开发者_如何学Crce 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];
I need to add 3 scope buttons to the bottom of the toolbar: "Topics","Messages","Stations" and have the first one selected by default. Can someone please tell me how to do this?
Oh.. nevermind.. found it..
searchBar.showsScopeBar = YES;
searchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"Flags", @"Listeners", @"Stations", nil];
精彩评论