2010-07-28 1 views
6

Je suis actuellement ce morceau de code pour la création d'un UISearchBar (adapté d'un exemple précédent stackoverflow):iPhone Objective-C ajouter programmation boutons de portée à un UISearchBar

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

je dois ajouter 3 boutons de portée au fond de la barre d'outils: "Sujets", "Messages", "Stations" et avoir le premier sélectionné par défaut. Est-ce que quelqu'un pourrait m'expliquer comment faire cela?

Répondre

15

Oh .. .. Nevermind trouvé .. il

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

Vous pouvez accepter votre propre réponse. – iDev

Questions connexes