隐藏键盘iphone sdk?

发布于 2024-11-01 00:25:48 字数 631 浏览 0 评论 0原文

我有一个 UISearchBar。我希望用户点击搜索后键盘立即消失...我确实尝试了 resignFirstResponder 但这不起作用。任何帮助将不胜感激,

- (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

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;
}

thanks
TC

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

转瞬即逝 2024-11-08 00:25:48

请确保以下事项。(我希望您正在谈论键盘的搜索按钮。)

  1. 您已将 searchBar 的 IBOutlet 与其变量 search 连接起来。
  2. 您没有在代码中的任何位置取消引用搜索变量(重新分配它)。
  3. 您的 - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar 方法与 searchBar 位于相同的 viewcontroller 中。
  4. 请 NSLog(@"Search Bar Instace : %@",search );在 viewDidLoad 方法和 searchBarSearchButtonClicked 中,并验证两个实例是否相同,如果不同,则您的 search 正在代码中的某个位置重新分配。
  5. 就在 [searchBar resignFirstResponder]; NSLog(@"isFirstResponder : %d",[searchbar isFirstResponder]); 之后和 NSLog(@"Next Responder : %@",[searchBar nextResponder]);
  6. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
    当您点击键盘的搜索按钮时正在调用方法?确保您的 后面没有添加键盘 responder(例如 textFieldtextView 或其他 searchBar) >searchBar 可能是无意的。也请通过xib检查。

谢谢,

Please make sure of following things.(I hope you are talking about search Button of keyboard.)

  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.

Thanks,

初心未许 2024-11-08 00:25:48

它应该通过在委托对象上实现响应方法来工作:

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

参考:http://www.iphonedevsdk.com/forum/iphone-sdk-development/7148-problem-uisearchbar-navigation-controller.html#post59467

It should work by implementing the respond methods at the delegate object:

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

Reference: http://www.iphonedevsdk.com/forum/iphone-sdk-development/7148-problem-uisearchbar-navigation-controller.html#post59467

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文