UISearchBar 点击X 按钮收键盘

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText;{
    NSLog(@"textDidChange---%@",searchBar.text);

    if (searchBar.text.length == 0) {
        [self performSelector:@selector(hideKeyboardWithSearchBar:) withObject:searchBar afterDelay:0];
        }

}

- (void)hideKeyboardWithSearchBar:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];
}

 

posted @ 2014-05-25 15:45  菜鸟程序猿  阅读(1710)  评论(0编辑  收藏  举报