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?
In your XIB file, you should have an App Delegate object (and some other things).
Right-clicking it should bring up a HUD list, where you’ll see each of your outlets (and, again, some other things).Find the
webberoutlet, and click the circle to its right. Then drag to yourWebView.What you’ve just done is linked your properties to your XIB objects. Skip this step, and your App Delegate won’t know what
webberis referring to.Also, note that in order to populate that HUD list, your properties need to be specifically tagged with
IBOutlet.