The 'search' fuction on my textfield keyboard isn't working

Discussion in 'iOS Programming' started by 2468, Oct 11, 2013.

  1. 2468, Oct 11, 2013
    Last edited by a moderator: Oct 11, 2013

    2468 macrumors newbie

    Oct 11, 2013
      -(IBAction)searchInfo: (id)sender 
        NSString *query = [googleBar.text stringByReplacingOccurrencesOfString:@" " withString:@"+"];
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"" , query]];
            NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [webView loadRequest:request];
        [textField resignFirstResponder];
        NSString *javascriptString = @"document.getElementsByClassName('g')[0].getElementsByTagName('a')[0].click()";
        [webView stringByEvaluatingJavaScriptFromString: javascriptString];
    So basically my 'Searchinfo' button searches whatever the users inputs into the textfield on Google and then displays the first search result. When the user is editing the textfield using the pop up keyboard, I've noticed that the keyboard's search function dosen't do the same thing as the 'Searchinfo' button. Here is my code for the keyboard;

    -(IBAction) returnKeyButton : (id) sender { 
      [self searchInfo:sender];
      [self resignFirstResponder];
    I have wired everything but I'm not sure why when I resign the keyboard using its search function it doesn't do the same as my button above, this being it taking the users input in the textfield and searching it onto Google and displaying the first search result. Thanks in advance
  2. ArtOfWarfare macrumors G3


    Nov 26, 2007
    Are you sure this code is getting called, and if so, how? If you're not sure it's getting called, you should check if it is or not, either by learning to use the debugger and setting breakpoints, or by inserting some NSLog statements.
  3. 2468 thread starter macrumors newbie

    Oct 11, 2013
    Thanks i checked but nothing till not getting what i want :(

Share This Page