2013-05-06 55 views
1

這是我在Stackoverflow上的第一個問題。我在編寫通用iOS應用程序時廣泛使用了SO。UISearchBar沒有專注於iPad分割視圖

我碰到了一個關於UISearchBar的問題: 我有一個通用的應用程序,帶有一個tableview和一個搜索欄。在iPhone上,tableview是主視圖控制器,在iPad上,它是splitViewController的masterViewController。 這兩個設備有不同的XIB,但它們共享相同的實現代碼。 搜索欄工作正常,除非我第一次向下滾動tableview。

當我激活了搜索欄與iPhone的按鈕與

[self.searchBar becomeFirstResponder]; 

表滾動一路攀升,搜索欄來考慮,鍵盤出現,我就可以開始打字。精細。

雖然在iPad上,tableview是UISplitView的一部分,當我調用becomeFirstResponder時,tableview不滾動,搜索欄不能進入視圖,並且我無法控制搜索欄(也不能點擊取消按鈕,因爲我沒有看到它)。雖然SearchDisplayController被激活,但因爲tableview變暗而導航欄移出視圖。

你能給我任何線索在哪裏看?我已經確定,一切都在廈門國際銀行有線起來......

乾杯, 鮑勃

+0

我應該提到self.searchbar是一個搜索欄的IBOutlet。 – Bob 2013-05-07 22:19:49

回答

1

我發現現在工作的解決辦法,但它是一個有些奇怪的是,解決方法只需要在iPad上... 只是打電話becomeFirstResponder上搜索欄前移動的tableView邊界的原點爲0,0。在iPhone上,這是「自動」發生的。

CGRect newBounds = self.mainTableView.bounds; 
    newBounds.origin.y = 0; 
    self.mainTableView.bounds = newBounds; 
0

我的方法

- (void)mockSearch:(NSTimer*)timer 
... 

[self.searchDisplayController.searchBar becomeFirstResponder]; 

它可以從網上下載http://blog.patrickcrosby.com/2010/04/27/iphone-ipad-uisearchbar-uisearchdisplaycontroller-asynchronous-example.html

插入串的例子。希望我的文章幫助你。

TC評論後添加:在DetailViewConroller我宣佈協議:

@protocol SearchBarController <NSObject> 
- (void) setSearchString: (NSString*) aString; 
@end 

而擺的UIButton與處理程序:

- (IBAction) pressSomeButton: (id) sender 
{ 
    [_myPopoverController presentPopoverFromRect: CGRectMake(0, 0, 1, 1) 
              inView: self.view 
         permittedArrowDirections: UIPopoverArrowDirectionUp 
             animated: YES]; 

    [self.searchDelegate setSearchString: @"123"]; 
} 

在GenericViewController界面添加SearchBarController協議。

實現的協議的方法:

​​

它的工作文件中縱向和橫向模式。

+0

嗨,我也遇到了這個例子。 首先,我沒有看到你想要做什麼,因爲當mockSearch被調用時,你實際上正在搜索並且搜索欄已經是第一個響應者,因爲你只是在其中鍵入了一些文本。 其次,你沒有得到我的問題的重點:當我在我的搜索欄上調用becomeFirstResponder時,它不在視圖中,我看不到我正在輸入的內容。 Thanx盡力幫助。 – Bob 2013-05-07 22:15:36

+0

好的,我編輯了我的答案。 – stosha 2013-05-08 08:16:35