Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
    // 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];

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?

like image 652
dpigera Avatar asked Jul 28 '10 10:07

dpigera


1 Answers

Oh.. nevermind.. found it..

searchBar.showsScopeBar = YES;
searchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"Flags", @"Listeners", @"Stations", nil];
like image 113
dpigera Avatar answered Nov 06 '22 05:11

dpigera