本文介绍了隐藏键盘iPhone SDK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个UISearchBar
.我希望用户点击搜索键后键盘就消失...我确实尝试过resignFirstResponder
,但是那没用.任何帮助将不胜感激
I have a UISearchBar
. I want the the keyboard to go away as soon as user hits search...i did try resignFirstResponder
but that didn't work. any help would be appreciated
- (void)viewDidLoad {
[super viewDidLoad];
self.title = NSLocalizedString(@"Songs", @"Search for songs");
NSMutableArray *array = [[NSArray alloc]initWithObjects: @"Book_1", @"Book 2", @"Book _ 4", nil];
self.booksArray = array;
[array release];
search.delegate=self;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
谢谢TC
推荐答案
请确保注意以下事项.(希望您在谈论键盘的搜索按钮.)
Please make sure of following things.(I hope you are talking about search Button of keyboard.)
- 您已将searchBar的
IBOutlet
与它的变量search
连接起来. - 您不会在代码的任何地方取消引用搜索变量(重新分配它).
- 您的
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
方法与searchBar所在的viewcontroller
位于相同的位置. - 请NSLog(@搜索栏实例:%@",搜索);在viewDidLoad方法和
searchBarSearchButtonClicked
中,并验证两个实例是否相同(如果不相同),则您正在search
中重新分配代码中的某个位置. - 在
[searchBar resignFirstResponder];
NSLog之后(@"isFirstResponder:%d",[searchbar isFirstResponder]);和NSLog(@"Next Responder : %@",[searchBar nextResponder]);
- 是
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
点击键盘的搜索按钮时调用方法?确保在searchBar
后面无意添加了键盘responder
(例如textField
,textView
或其他searchBar
).请同时通过xib进行检查.
- You have connected your
IBOutlet
of searchBar with its variablesearch
. - You are not de-referring search variable anywhere in your code(reassigning it).
- Your
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
method is in sameviewcontroller
as searchBar is in. - Please NSLog(@"Search Bar Instace : %@",search); in viewDidLoad method and
searchBarSearchButtonClicked
and verify that both instances are same if not then you aresearch
is getting reassigned somewhere in code. - Just after
[searchBar resignFirstResponder];
NSLog(@"isFirstResponder : %d",[searchbar isFirstResponder]); andNSLog(@"Next Responder : %@",[searchBar nextResponder]);
- Is
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
method is being called when you tap search Button of keyboard? Make sure there are no keyboardresponder
(liketextField
,textView
or othersearchBar
) is added behind yoursearchBar
may be unintentionally. Please check it through xib also.
谢谢
这篇关于隐藏键盘iPhone SDK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!