iPhone Objective-C programmatically adding scope b

2019-04-08 01:26发布

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?

1条回答
Lonely孤独者°
2楼-- · 2019-04-08 01:57

Oh.. nevermind.. found it..

searchBar.showsScopeBar = YES;
searchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"Flags", @"Listeners", @"Stations", nil];
查看更多
登录 后发表回答