2

I've got an app with the following class:

@interface SearchViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate>
@property (nonatomic, retain) IBOutlet UISearchBar *search;

How can I customize UISearchBar? I'd like to add a segmented button to allow for search options (and/or/phrase).

Matt
  • 556
  • 1
  • 4
  • 18

1 Answers1

7

Try this:

search.showsScopeBar = YES;
search.scopeButtonTitles = [NSArray arrayWithObjects:@"Button",@"Titles",@"Go",@"Here",nil];

That gives you the standard segmented control for search. You can use search.selectedScopeButtonIndex to check its state.

Tom
  • 3,831
  • 1
  • 22
  • 24
  • 3
    thanks. I note for future readers that you also have to add [search sizeToFit], otherwise the search bar will draw at its original size (i'm setting showsScopeBar in viewDidLoad). – Matt Mar 18 '10 at 23:12
  • If you are going to filter each scope, what will your `cellForRowAtIndexPath` look like? -- I have a search function and two scope: `City` and `Church`, the search function works, however it will display a blank cell. My `cellForRowAtIndexPath` looks like this: `if (tableView == self.searchDisplayController.searchResultsTableView) { if ([searchBar scopeButtonTitles]) { cell.textLabel.text = [[filteredResult objectAtIndex: indexPath.row] objectForKey: @"Places"]; }` Please advice. – Jahm Dec 29 '12 at 11:04