检测UISearchBar焦点在文本字段上

时间:2010-01-19 18:20:38

标签: iphone objective-c uitextfield uisearchbar

有没有办法检测用户是否点击了搜索栏文本字段并且键盘出现了?

3 个答案:

答案 0 :(得分:11)

来自docs

  • searchBarTextDidBeginEditing:
  • searchBarCancelButtonClicked:

答案 1 :(得分:8)

如果要实现UISearchBarDelegate,应该调用的第一个方法是:

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

这是课程参考:

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UISearchBarDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UISearchBarDelegate/searchBarShouldBeginEditing

答案 2 :(得分:3)

您的搜索栏委托应该收到searchBarTextDidBeginEditing:message。