1

I'm making a simple app, to load up a single URL, I have the following code

webberAppDelegate.h

#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
@interface webberAppDelegate : NSObject <NSApplicationDelegate> {
    NSWindow *window;
    WebView *webber;
}

@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet WebView *webber;
@end

webberAppDelegate.m

#import "webberAppDelegate.h"

@implementation webberAppDelegate

@synthesize window;
@synthesize webber;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    NSString *urlString = @"http://www.apple.com";
    // Insert code here to initialize your application 
    [[webber mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
}

@end

What do I have to do in Interface builder? I've added the Web View, do I need to link it in any way?

Thing is I added simple text field(and linked it to the web view) and it loads the URL just fine when I enter it there, however it doesn't with this code, any ideas?

Saulius Antanavicius
  • 1,371
  • 6
  • 25
  • 55
  • [Automatic Reference Counting](http://www.mikeash.com/pyblog/friday-qa-2011-09-30-automatic-reference-counting.html), which is enabled by default for all new projects since Xcode 4.2. If you are using it, you should change that property declaration to `@property (strong) IBOutlet WebView *webber;` or your `WebView` instance might be deallocated. – Rob Keniger Nov 30 '11 at 00:53
  • 2
    You might also want to ensure that your web view is hooked up in your XIB. – Rob Keniger Nov 30 '11 at 00:54
  • When you say hooked up, what do you mean? It's there, what should I hook it up to in the xib? – Saulius Antanavicius Nov 30 '11 at 11:39
  • @Rob Keniger I'm running 3.2.2 so I doubt thats the case? – Saulius Antanavicius Dec 01 '11 at 17:01

1 Answers1

6

In your XIB file, you should have an App Delegate object (and some other things).

Objects

Right-clicking it should bring up a HUD list, where you'll see each of your outlets (and, again, some other things).Find the webber outlet, and click the circle to its right. Then drag to your WebView.

Linking

What you've just done is linked your properties to your XIB objects. Skip this step, and your App Delegate won't know what webber is referring to.

Also, note that in order to populate that HUD list, your properties need to be specifically tagged with IBOutlet.

Patrick Perini
  • 22,555
  • 12
  • 59
  • 88