2010-07-28 27 views
6

hiện tôi đoạn mã này để tạo ra một UISearchBar (chuyển thể từ một ví dụ stackoverflow trước):iPhone Objective-C lập trình thêm nút phạm vi để một 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]; 

Tôi cần thêm 3 nút phạm vi xuống phía dưới của thanh công cụ: "Chủ đề", "Tin nhắn", "Kênh" và có tùy chọn đầu tiên được chọn theo mặc định. Ai đó có thể cho tôi biết làm thế nào để làm điều này?

Trả lời

15

Oh .. nevermind .. tìm thấy nó ..

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

Bạn có thể chấp nhận câu trả lời của riêng bạn. – iDev

Các vấn đề liên quan