Google Search Bar in Browser

Discussion in 'iOS Programming' started by Programmer, Jun 16, 2009.

  1. Programmer macrumors member

    Programmer

    Joined:
    Jun 16, 2009
    #1
    could someone please help me figure out how to put a google search bar in the web browser I'm making in xcode.:eek:
     
  2. Nukemkb macrumors 6502a

    Nukemkb

    Joined:
    Mar 12, 2006
    Location:
    Columbia, SC
    #2
    hmm. select View, then 'customize toolbar', then drag it and drop it....
     
  3. veterator macrumors member

    veterator

    Joined:
    Jan 18, 2007
    Location:
    Oklahoma
  4. Nukemkb macrumors 6502a

    Nukemkb

    Joined:
    Mar 12, 2006
    Location:
    Columbia, SC
    #4
    Good question!
     
  5. Programmer thread starter macrumors member

    Programmer

    Joined:
    Jun 16, 2009
    #5
    xcode

    no i'm i am trying to program it into my web browser i'm making in xcode.
     
  6. Thomas Harte macrumors 6502

    Joined:
    Nov 30, 2005
    #6
    How do you currently have your webView set up to get page URLs? Do you have it connected to an NSTextField via takeStringURLFrom: or are you pushing URLs to it with setMainFrameURL:?

    In either case, you'll want to set yourself up as a delegate of a second NSTextField, do something like this when you receive textDidEndEditing: from it:

    Code:
    NSString *searchURL = [NSString stringWithFormat:@"http://www.google.com/search?q=%@", [googleField stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    Then set searchURL to your normal URL bar, possibly passing it to the WebView as well if you have the link between the two going through your own code.

    The main observations are merely that you need to:

    (i) escape the search string (eg, to turn a space into %20 so that it works in a URL); and
    (ii) add http://www.google.com/search?q= to the start to turn it into a Google search URL.

    Then just treat that identically to a URL directly entered by the user.
     
  7. Programmer thread starter macrumors member

    Programmer

    Joined:
    Jun 16, 2009
    #7
    Thanks

    thanks
    what i'v been having trouble with is when i try to retrieve the text from the google search bar in the .h file then do the @synthesize in the .m file to put it into this string of code

    HTML:
    NSString *searchURL = [NSString stringWithFormat:@"http://www.google.com/search?q=%@", [GoogleSearchField stringValue]];
    i am used to programing on the iphone this is what i would normally do so i don't know if it is different on a mac
     
  8. Programmer thread starter macrumors member

    Programmer

    Joined:
    Jun 16, 2009
    #8
    url field problem

    i'm making a web browser but when i run this code

    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
    NSString *searchURL = [NSString stringWithFormat:mad:"http://", [urlField stringValue], NSString stringWithFormat:mad:".com"];
    [textField resignFirstResponder];
    [myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[textField text]]]];


    return YES;
    }

    i get this

    HTML:
    Expected expression before NSString
    can anyone help
     
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    First (and we really need to sticky this for this forum), if you're going to include cope snippets, please enclose them in [ CODE ][ /CODE ] tags (spaces removed). These tags are easily accessed via the # icon in the toolbar.

    Second, your problem starts here:
    Code:
    - (BOOL)textFieldShouldReturnUITextField *)textField
    You probably want something like this instead:
    Code:
    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    ...and continues here:
    Code:
    NSString *searchURL = [NSString stringWithFormat:@"http://", [urlField stringValue], NSString stringWithFormat:@".com"];
    You probably want something like this:
    Code:
    NSString *searchURL = [NSString stringWithFormat:@"http://%@%@", [textField text], @".com"];
     
  10. autorelease macrumors regular

    Joined:
    Oct 13, 2008
    Location:
    Achewood, CA
    #10
    Learn about strings. That line is nonsense.

    What you want is

    Code:
    NSString *searchURL = [NSString stringWithFormat:@"http://%@.com", [urlField stringValue]]
     

Share This Page