本文介绍了iPhone Objective-C以编程方式将范围按钮添加到UISearchBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前用于创建UISearchBar的这段代码(改编自之前的stackoverflow示例):

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

我需要在工具栏的底部添加3个范围按钮:主题,消息 ,站并默认选择第一个。有人可以告诉我怎么做吗?

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

这篇关于iPhone Objective-C以编程方式将范围按钮添加到UISearchBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 23:57