2012-09-25 32 views
0

我很難與UISearchDisplayController。在我的情況下,我有一個UIView推到一個navgation控制器。在UIView我有一個UITableViewUIToolbar。在UITableView我使用UISearchDisplayController添加一個工具欄到UISearchDisplayController的結果

<img></img>

工具欄按鈕來添加額外的過濾選項來搜索。我的問題是,我無法弄清楚,如何在UISearchDisplayController的結果表視圖的底部添加工具欄。

enter image description here

什麼是去一個工具欄添加到結果的方式?

回答

0

我終於設法解決了我的問題。

而不是使用UISearchDisplayController我只將UISearchBar添加到我的UITableView並複製UISearchDisplayController與UISearchBarDelegate方法的行爲。

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText 
{ 
    [self setSearchText:searchText]; 
    [self filterCards]; 
} 

- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope 
{ 
    [self setScopeIndex:selectedScope]; 
    [self filterCards]; 
} 

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar 
{ 
    // Move searchbar to table view 
    [self.chapterSearchBar removeFromSuperview]; 
    [self.chapterTableView addSubview:[self chapterSearchBar]]; 

    // Show navigation controller 
    [self.navigationController setNavigationBarHidden:NO animated:YES]; 

    // Hide scope bar an resize 
    [searchBar setShowsScopeBar:NO]; 
    [searchBar sizeToFit]; 

    // Hide cancel button 
    [searchBar setShowsCancelButton:NO animated:YES]; 

    // Resize table view 
    CGRect tableViewRect = [self.chapterTableView frame];  
    tableViewRect.origin.y = 0; 
    [self.chapterTableView setFrame:tableViewRect]; 

    // Hide keyboard 
    [searchBar resignFirstResponder]; 
    [self setSearchText:@""]; 
    [self filterCards]; 
} 

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar 
{ 
    [searchBar resignFirstResponder]; 
} 

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar 
{ 
    // Move searchbar to controller view 
    [self.chapterSearchBar removeFromSuperview]; 
    [self.view addSubview:[self chapterSearchBar]]; 

    // Hide navigation controller 
    [self.navigationController setNavigationBarHidden:YES animated:YES]; 

    // Show scope bar an resize 
    [searchBar setShowsScopeBar:YES]; 
    [searchBar sizeToFit]; 

    // Show cancel button 
    [searchBar setShowsCancelButton:YES animated:YES]; 

    // Resize table view 
    CGRect tableViewRect = [self.chapterTableView frame];  
    tableViewRect.origin.y = 44; 
    [self.chapterTableView setFrame:tableViewRect]; 

    return YES; 
} 
0

如果任何人的好奇如何解決這一問題還在使用UISearchDisplayController(清潔劑可能),只需設置工具欄的項目到您的視圖控制器的toolbarItems而搜索是積極的:

self.navigationController.toolbarHidden = NO; 
self.toolbarItems = optionsToolbar.items; 

UISearchDisplayController根據toolbarItems保留視圖控制器的工具欄,所以這可能已經爲你完成了。如果僅在搜索過程中使用工具欄,這會很有用。