2012-08-02 103 views
0

爲了瞭解UISearchDisplayController是如何工作的,我寫在viewDidLoad方法如下代碼:爲什麼UISearchBar顯示不正確?

UISearchBar * searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 40.0f)] autorelease]; 
searchBar.delegate = self; 
searchBar.showsCancelButton = YES; 

_searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self]; 
_searchController.delegate = self; 
_searchController.searchResultsDataSource = self; 
_searchController.searchResultsDelegate = self; 

[_searchController setActive:YES animated:YES]; 
[_searchController.searchBar becomeFirstResponder]; 

但是當我運行我的代碼的UISearchBar不被顯示,你可以在圖片中看到。

回答

1

創建UISearchBarcontroller它不錯,但在UIViewController中沒有添加。所以你可以在uiviewcontroller中添加UISearchBarcontroller。

編碼:

[self.view addsubview:_searchController];

相關問題