Help with cocoa tutorial (new to cocoa from A.S.)

Discussion in 'Mac Programming' started by Heli0s38, Jun 5, 2009.

  1. macrumors newbie

    Joined:
    May 4, 2009
    #1
    Hello!

    Im used to using xcode for applescripting programs with GUIs but then decided to use a tutorial for cocoa to write a simple web browser for my friend (applescript for 10.5 isnt very backward compatible with 10.4, there were bugs whenever he ran it which did not show up when i ran it in 10.5)

    heres the snippet im stuck on. (the first part.. aaaahehehh.... :S) and i do have basic knowledge of ObjC



    Using Xcode, create a document-based Cocoa application. Your new project file will already contain the needed classes and interface files to support multiple windows (namely MyDocument.h, MyDocument.m, and MyDocument.nib).

    Add the Web Kit frameworks to your project.

    Open MyDocument.nib using Interface Builder and drag a WebView from the Cocoa—GraphicsViews palette to your document window.

    Create a webView outlet in MyDocument.h and read the file into Interface Builder.

    Connect the webView outlet of the File’s Owner to the WebView object you created in the previous step.

    Add code to MyDocument.m to load a default page. You can add this code fragment to the windowControllerDidLoadNib: method:

    NSString *urlText = [NSString stringWithString:mad:"http://www.apple.com"];
    [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
    Build and run your application.


    i highlighted where im stuck in bold. i do not know how to create an outlet in xcode, i do know how to in IB tho, but it doesnt seem to want to work that way.

    can somebody clear this up for me? sorry!
     
  2. macrumors 6502

    Joined:
    Feb 16, 2007
    Location:
    Waterloo, Ontario
    #2
    The main problem is that the tutorial is for the old versions of Xcode and Interface Builder. Things like "read the file into Interface Builder" are no longer necessary. Your classes should stay up to date automatically. When possible, try to stick to recent tutorials. Working through "Cocoa Programming for Mac OS X" is really the best use of time for programmers new to Cocoa IMHO.

    All you need to do is declare the outlet in the header file and connect the outlet in IB. In the curly brackets following the @interface portion of your header file, include the following:

    IBOutlet NSWebView *webView;

    You then just need to drag the web view into your document window in IB. If you control drag from the owner to the web view, then select the outlet, you should be done.

    Best of luck

    Luke
     
  3. thread starter macrumors newbie

    Joined:
    May 4, 2009
    #3
    thanks for the help Luke. the outlet now pops up in IB, but when i go to control drag from file owner to the web view in the Doc window, i can only select the entire window, and not the webview itself with the blue line. so i cant connect the outlet to the webview, only the window..

    am i doing something wrong?
     
  4. macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #4
    Instead try selecting the webview in IB, and make sure the Ispector is up via Menu option Tools->Inspector.

    In the inspector window click the tab that has the blue circle with a white arrow.

    These are the outlets forthe current object, you can drag from the circle beside "New Referencing Outlet" and drag it to File's Owner.
     
  5. thread starter macrumors newbie

    Joined:
    May 4, 2009
    #5
    i dont have a "New Referencing Outlet" option in IB when i select the webview. i am using xcode 3.0.0, if that helps.
     
  6. macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #6
    Then it sounds like something is wrong. Try dragging a new webview onto your window canvas from the objects list.
     
  7. macrumors 6502

    Joined:
    Feb 16, 2007
    Location:
    Waterloo, Ontario
    #7

    That was my fault. The class name is actually just "WebView" - not "NSWebView". The class name should be changed in the header. You should be able to make the connection once the change has been made.

    When you have trouble making connections in IB, make sure your class name when declaring the outlet matches the class name of the IB object exactly. You can check the class name of IB objects in the inspector under the "View Identity" tab.
     
  8. thread starter macrumors newbie

    Joined:
    May 4, 2009
    #8
    Bingo. thank you lucas! and your idea worked too after i fixed my header file jared. thanks to you both!
     

Share This Page