New to Xcode, need some help with something...

Discussion in 'Mac Programming' started by MartinAppleGuy, Jul 14, 2014.

  1. MartinAppleGuy macrumors 68020


    Sep 27, 2013
    Hi there, I download Xcode last night and have started work on a basic web browser. I know quite a bit of Visual Basic but don't know any Obj C or Xcode. Here is what I have done:

    All of the work I have done is through the mainmenu.xib area. I have added a webview, and added a few buttons for back and forward that I have linked to the webview for back and forward (by right clinking the webview which brings up a grey box and then clicking and dragging from the correct circles to the buttons). I have also added the webkit framework. I have also added a textbox to act as a search box for the browser and it works as long as I type in the full url of a website. I have wrote no code.

    This is what I want to do:

    I wish for search box to only need the search query (ie what a user is searching) then search using Google (I'd like for it to work by pressing enter, or the "Go" button. How can I go about doing this (I'm sure I will have to make a string var, then add the google url string and the query together then making that search in the webview, but I don't know how to do that in Xcode).

    Thank you :)

  2. Dookieman macrumors 6502

    Oct 12, 2009
    You're correct that you need string variable to do what you want.

    You're going to need a couple of things. A string with the google address, and a string you'll build from the textbox.

    Something similar to this (I'm away from a Mac now and just doing thing from memory) is an IDEA on what you need to do. I can't test it since I'm not on my Mac.

    //Textbox String
    NSString *userSearch = [[NSString alloc] init];
    userSearch = myTextBox.text; <-The textbox that you placed in your storyboard

    //Google's URL
    NSString *googleURL = [[NSString alloc] init];

    //Something like this, i'm not sure exactly what google's search string looks like
    googleURL = [NSString stringWithFormat:mad:"", userSearch]; <- The "%@" is a placeholder for your userSearch string.

    Then you can use your webview to use "googleURL" when you need to provide it a URL.

Share This Page