iPhone Objective-C programmatically adding scope buttons to a UISearchBar

我是研究僧i 提交于 2019-12-06 01:05:56

问题


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:


Oh.. nevermind.. found it..

searchBar.showsScopeBar = YES;
searchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"Flags", @"Listeners", @"Stations", nil];


来源:https://stackoverflow.com/questions/3351887/iphone-objective-c-programmatically-adding-scope-buttons-to-a-uisearchbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!