【问题标题】:UISearch Bar Not Being Updated By Keyboard Input键盘输入未更新 UI 搜索栏
【发布时间】:2012-12-05 10:41:51
【问题描述】:

我有一个 ViewController,其子视图包含 UISearchBar。当我单击搜索栏时,会出现键盘,我可以使用取消按钮将其关闭。问题似乎是当用户点击键盘按钮时它不接受任何输入。

#pragma mark -
#pragma mark SEARCH METHODS
#pragma mark -


- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {

    self.mainSearchBar.showsCancelButton = YES;

    return YES;
}


- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{

    [self.mainSearchBar resignFirstResponder];

    self.mainSearchBar.showsCancelButton = NO;

    self.mainSearchBar.text = @"";

}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {

    [self.mainSearchBar resignFirstResponder];

}

以前有没有人遇到过这个问题或知道如何解决?

** 更新 *****

事实证明,在尝试编辑 UISearchBar 时,Siri 会起作用。尽管如此,键盘输入仍然没有运气。我认为这与 UISearchBar 位于 UIView 然后添加为子视图这一事实有关。不过不知道怎么解决。

** 更新 2 ***** 将搜索框移到主 UIView 中,我仍然遇到同样的错误。我想知道它现在是否与导航控制器有关。

【问题讨论】:

    标签: ios xcode ios5 ios6


    【解决方案1】:

    确保应用委托具有 [self.window makeKeyAndVisible]。希望它能解决您的问题。

    【讨论】:

    • 嗨,刚刚检查了委托确实有这个方法
    【解决方案2】:

    检查您是否在 viewController 的 .h 文件中添加了 UISearchBarDelegate。

    【讨论】:

    • 您好,刚刚添加了代表,但没有任何区别。除了按下按键时更新 UISearchBar 之外,一切正常。
    • 试试这个委托方法:- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar { }
    • 刚刚添加并在其中放置了一个 NSLog。它会在启动时打印日志,但更新仍然没有运气。
    【解决方案3】:

    也试试这个代码:

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

    【讨论】:

    • 嗨,这未被识别,因此没有记录任何内容。
    【解决方案4】:

    这必须与SearchBar 相对于ViewControllerview 的呈现方式有关。你为什么要把SearchBar 变成另一个viewsubview 而不是ViewControllerview 的子视图?

    【讨论】:

    • 我有一个位于底部的 UIView。然后我在上面有一个 UIView 作为菜单(想想 Facebook 侧菜单界面),然后在上面我有一个 UIView 来保存内容和 UISearchBar。这个想法是当用户点击一个按钮时,顶视图会滑动。
    【解决方案5】:

    问题解决了,在上一个帖子Keyboard and cursor show, but I can't type inside UITextFields and UITextViews找到答案

    事实证明,在 IOS6 中,Visible at Launch 检查需要点击选项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-03
      • 2011-03-08
      • 1970-01-01
      • 1970-01-01
      • 2018-02-20
      • 2020-09-07
      • 2023-03-15
      • 1970-01-01
      相关资源
      最近更新 更多