2011-01-14 188 views
0

我很抱歉的圖像,但我不知道更好的方式來解釋我的問題。 這是我開始申請時的視圖,一切都很好。 alt text 這是當我旋轉手機,搜索欄頂部現在有點下導航欄。 alt text 我開始搜索並取消它。 alt text 現在搜索欄並未覆蓋導航欄,但導航欄的高度較小。 alt text 當我走到垂直視圖時,導航欄仍然很小,我在它下面有一個黑洞。 alt text 我找不到爲什麼發生這種情況,有什麼幫助?SearchBar旋轉問題

這是我如何創建並添加搜索欄代碼:

- (void) loadView 
{ 
    [super loadView]; 

    sBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,320,45)]; 
    sBar.delegate = self; 
    sBar.placeholder = @"Search";  
    self.tableView.tableHeaderView = sBar; 

    UISearchDisplayController *searchDC = [[UISearchDisplayController alloc] initWithSearchBar:sBar contentsController:self]; 

    self.searchDisplayController = searchDC;  

    searchDC.delegate = self; 
    searchDC.searchResultsDataSource = self; 
    searchDC.searchResultsDelegate = self; 

    [sBar release]; 
    [searchDC release]; 
} 

我沒有專門用於導航或搜索欄更改旋轉的方法什麼。

+0

圖片沒問題,但我們無法幫助沒有code/xib – 2011-01-14 09:11:08

+0

我更新了代碼的問題,我如何添加搜索欄。 – 1110 2011-01-14 09:23:57

回答

3

驗證您的所有視圖幀:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

如果他們都不行設置正確的框架。

0

最簡單的解決方案是將UISearchBar添加到UITableView標頭。在這種情況下,所有工作人員都將被開箱即用。

在切換視圖和旋轉時,設置框架會導致UISearchBar寬度問題。我在基於標籤的應用中遇到過這個問題。是的,測試用例不容易複製,但它仍然是一個錯誤。