【问题标题】:The 'search' function on my textfield keyboard isn't working我的文本字段键盘上的“搜索”功能不起作用
【发布时间】:2013-10-11 07:11:05
【问题描述】:
    -(IBAction)searchInfo: (id)sender 
{
    NSString *query = [googleBar.text stringByReplacingOccurrencesOfString:@" " withString:@"+"];
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.co.uk/search?q=%@" , query]];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];


    [webView loadRequest:request];
    [textField resignFirstResponder];

    NSString *javascriptString = @"document.getElementsByClassName('g')[0].getElementsByTagName('a')[0].click()";

    [webView stringByEvaluatingJavaScriptFromString: javascriptString];
}

所以基本上我的“搜索信息”按钮会搜索用户在 Google 上的文本字段中输入的任何内容,然后显示第一个搜索结果。当用户使用弹出式键盘编辑文本字段时,我注意到键盘的搜索功能与“搜索信息”按钮的作用不同。这是我的键盘代码;

- (IBAction)ReturnKeyButton:(id)sender 
{ 

    [sender resignFirstResponder];

}

我已经连接了所有东西,但我不知道为什么当我使用它的搜索功能退出键盘时,它的作用与我上面的按钮不同,这是因为它需要用户在文本字段中输入并将其搜索到 Google并显示第一个搜索结果。

【问题讨论】:

    标签: iphone ios objective-c xcode uitextfield


    【解决方案1】:

    如果您希望返回键产生与 searchInfo 按钮相同的操作,您可能希望从 returnKeyButton 调用您的 searchInfo 方法

    例如:

    -(IBAction) returnKeyButton:(id) sender { 
      [self searchInfo:sender];
      [self resignFirstResponder];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-02
      • 1970-01-01
      • 1970-01-01
      • 2020-01-12
      • 1970-01-01
      • 2017-07-07
      • 1970-01-01
      • 2022-01-02
      相关资源
      最近更新 更多