Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Heli0s38

macrumors newbie
Original poster
May 4, 2009
8
0
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!
 

lucasgladding

macrumors 6502
Feb 16, 2007
319
1
Waterloo, Ontario
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
 

Heli0s38

macrumors newbie
Original poster
May 4, 2009
8
0
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?
 

jared_kipe

macrumors 68030
Dec 8, 2003
2,967
1
Seattle
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.
 

Heli0s38

macrumors newbie
Original poster
May 4, 2009
8
0
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.
 

jared_kipe

macrumors 68030
Dec 8, 2003
2,967
1
Seattle
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.

Then it sounds like something is wrong. Try dragging a new webview onto your window canvas from the objects list.
 

lucasgladding

macrumors 6502
Feb 16, 2007
319
1
Waterloo, Ontario
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?


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.
 

Heli0s38

macrumors newbie
Original poster
May 4, 2009
8
0
Bingo. thank you lucas! and your idea worked too after i fixed my header file jared. thanks to you both!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.