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不被顯示,你可以在圖片中看到。