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

    Joined:
    Oct 11, 2013
    #1
    Code:
      -(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];
    }
    
    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;

    Code:
    -(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 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    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

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

Share This Page