2012-12-27 85 views
1

我試圖在我的項目中實現一個搜索欄。當我按下鍵盤按鈕時,SearchBar不起作用

我已經創建了搜索欄的出口,已經設置了委託,但是當我按下任何鍵盤按鍵,從這個按鈕的值不會出現在UISearchBar

任何人能告訴我爲什麼嗎?

- (void)searchBarSearchButtonClicked:(UISearchBar *)aSearchBar { 

    // When the search button is tapped, add the search term to recents and conduct the search. 
    NSString *searchString = [aSearchBar text]; 
    NSLog(searchString); 
} 
+0

您是否實施了UISearchBarDelegate協議? – LuisEspinoza

+0

是的@界面Tela1ViewController:UIViewController { – Ladessa

+0

問題是,當我數字,值不會出現在酒吧......是因爲我什麼也沒有... – Ladessa

回答

0

我已經錯過了的appDelegate下面的代碼,applicationDidFinishLauching

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
[self.window makeKeyAndVisible]; 

現在的搜索欄工作正常!

1

也許你忘了實現此方法:

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar 
{ 
    return YES; 
} 

通過返回YES你 「說:」 你接受編輯。

編輯

你甚至都不需要實現這個方法,在默認情況下一個UISearchBar接受編輯。
不需要額外的方法。

可以肯定的,我只是做了以下內容:

  • 拖在廈門國際銀行文件中的搜索欄;
  • 通過xib將委託綁定到我的視圖控制器;
  • 已實施searchBarSearchButtonClicked:並在其上放置斷點。

完美地工作。請確保您所做的一切都是正確的。

+0

是的,我忘了。但是現在,我已經實現了這個方法,並沒有在這個方法中加入 – Ladessa

+0

- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { return YES; } – Ladessa

+0

step in searchBarShouldBeginEditing當我點擊進入searchBar時,但當我的數字... – Ladessa

0

我已經忘了這個方法

-(BOOL) searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { 
    return YES; 
} 
+0

但不工作太 – Ladessa

+0

這並不需要。 –

+0

他們是什麼問題? :( – Ladessa

相關問題