Cocoa WebView does not load URL when loading application

I am making a simple application to download 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 need to do in the interface builder? I added a web view, do I need to link it in any way?

Thing: I added a simple text box (and linked it to the web view) and it loads the url just fine when I enter it there, however it is not with this code, any ideas?

+1
source share
1 answer

Your XIB file must have an application delegation object (and some other things).

Objects

Right-click on the HUD list, where you will see each of its points (and, again, some other things). Find the output line of webber and click on the circle on the right. Then drag it to the WebView .

Linking

What you just did is related to your properties with your XIB objects. Skip this step and your application delegate will not know what webber means.

Also note that in order to populate this HUD list, your properties must be specially marked with IBOutlet .

+6
source

Source: https://habr.com/ru/post/902981/


All Articles