2012-02-28 24 views
3

我想我在iOS 5.0中發現了一個關於UISearchBar的bug,它的範圍欄。我最初顯示在XIB中啓用的範圍欄。UISearchBar範圍欄iOS 5.0的錯誤?

運行期間,範圍欄顯示正確。但是,當點擊搜索文本框並單擊取消按鈕時,範圍欄將從屏幕上移除。屏幕區域仍然可見。查看屏幕截圖。

UISearchBar still shows scope bar view area 如果有人對如何解決此問題有一個想法,請讓我知道。

謝謝。凱。

+0

我有同樣的問題。設置searchBar.showsScopeBar沒有視覺效果。 showsScopeBar getter返回YES,但不會出現範圍條。 – Dustin 2012-04-09 21:16:48

回答

0

請澄清你的期望/想要發生的事情。有幾種代表方法。這裏有兩件事情我在SearchBarViewController做:

首先,我做VC是委託:

- (void)viewDidLoad { 
    searchBar.delegate = self; 
} 

關閉並返回到呈現視圖控制器(我的搜索框是模態):

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { 
    [[self presentingViewController] dismissModalViewControllerAnimated:YES]; 
} 

過濾:

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { 
    [self filterContentForSearchText:searchString scope: 
    [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]]; 

    // Return YES to cause the search result table view to be reloaded. 
    return YES; 
} 

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption { 
    [self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope: 
    [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]]; 

    // Return YES to cause the search result table view to be reloaded. 
    return YES; 
} 

祝你好運,

達明

+0

感謝您的快速回復。我想強制範圍欄始終保持可見狀態。我甚至實現了UISearchBar的子類... – Kay 2012-02-28 10:05:37

+0

您是否覆蓋searchBarCancelClicked:在委託中確保它沒有做任何事情?另外,你使用的是UISearchDisplayController嗎?我明白你的UISearchBar,但控制器呢?我記得我沒有在IB提供的UISearchDisplayController,使用UISearchBar時遇到了問題。我只測試了我自己的代碼,當我點擊取消時,tableview清除。這就是你想要發生的事情嗎? – 2012-02-28 10:19:00

+0

是的,我使用UISearchDisplayController,是的,我也沒有實現searchBarCancelClicked:沒有結果! :-( – Kay 2012-02-28 10:24:33

4

嘗試實施「searchBarShouldEndEditing」代表當搜索欄中存在重新啓用範圍吧。

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar 
{ 
    self.searchBar.showsScopeBar = YES; 
    [self.searchBar sizeToFit]; 
    self.tableView.tableHeaderView = self.searchBar; 
    return YES; 
} 

你可以閱讀更多有關此解決方案here