隐藏键盘iPhone SDK? [英] Hiding keyboard iphone sdk?

查看:75
本文介绍了隐藏键盘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.)

  1. 您已将searchBar的IBOutlet与它的变量search连接起来.
  2. 您不会在代码的任何地方取消引用搜索变量(重新分配它).
  3. 您的- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar方法与searchBar所在的viewcontroller位于相同的位置.
  4. 请NSLog(@搜索栏实例:%@",搜索);在viewDidLoad方法和searchBarSearchButtonClicked中,并验证两个实例是否相同(如果不相同),则您正在search中重新分配代码中的某个位置.
  5. [searchBar resignFirstResponder]; NSLog之后(@"isFirstResponder:%d",[searchbar isFirstResponder]);和NSLog(@"Next Responder : %@",[searchBar nextResponder]);
  6. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar 点击键盘的搜索按钮时调用方法?确保在searchBar后面无意添加了键盘responder(例如textFieldtextView或其他searchBar).请同时通过xib进行检查.
  1. You have connected your IBOutlet of searchBar with its variable search.
  2. You are not de-referring search variable anywhere in your code(reassigning it).
  3. Your - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar method is in same viewcontroller as searchBar is in.
  4. Please NSLog(@"Search Bar Instace : %@",search); in viewDidLoad method and searchBarSearchButtonClicked and verify that both instances are same if not then you are search is getting reassigned somewhere in code.
  5. Just after [searchBar resignFirstResponder]; NSLog(@"isFirstResponder : %d",[searchbar isFirstResponder]); and NSLog(@"Next Responder : %@",[searchBar nextResponder]);
  6. Is - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar method is being called when you tap search Button of keyboard? Make sure there are no keyboard responder(like textField,textView or other searchBar) is added behind your searchBar may be unintentionally. Please check it through xib also.

谢谢

这篇关于隐藏键盘iPhone SDK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆