2011-09-29 61 views
0

我已經使用以下代碼在我的iPad應用程序的表格中添加了UISearchBar。該表位於我的分割視圖控制器的左側。以編程方式添加UISearchBar - Bar在啓動時關閉屏幕 - iPad

問題是,當應用程序啓動搜索欄是奇怪的離屏幕左 - 你可以看到它的最後幾個像素。如果你點擊它,或者向下滾動並返回,它會自行恢復,看起來應該如此。

任何人都可以提出如何解決這個問題嗎?

感謝

searchBar = [[UISearchBar alloc] init]; 
self.tableView.tableHeaderView = searchBar; 

searchController = [[UISearchDisplayController alloc] 
        initWithSearchBar:searchBar 
        contentsController:self]; 

searchBar.delegate = self; 
searchController.delegate = self; 
searchController.searchResultsDelegate=self; 
searchController.searchResultsDataSource=self; 

回答

3

你可以嘗試使用像框架創建的UISearchBar:

CGRect searchViewFrame = CGRectMake(33, 33, 264, 31); 

或任何尺寸或起源。

像其他資源,你可以一個UIView內創建的UISearchBar,這UIView的添加到的UITableView:

UIView *containerSearch = [[UIView alloc] initWithFrame: searchViewFrame]; 
searchBar = [[UISearchBar alloc] init]; 
[containerSearch addSubview: searchBar]; 
self.tableView.tableHeaderView = containerSearch;