可可的WebView在加载应用程序时不会加载URL [英] Cocoa's WebView does not load a URL upon loading the app

查看:69
本文介绍了可可的WebView在加载应用程序时不会加载URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个简单的应用程序,以加载单个URL,我有以下代码

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

webberAppDelegate.h

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

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

我该怎么办在界面生成器中?我已经添加了Web视图,是否需要以任何方式链接它?

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

我要添加简单的文本字段(并将其链接到Web视图),当我在其中输入URL时,它会很好地加载URL,但是此代码不包含任何想法吗?

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?

推荐答案

在您的XIB文件中,您应该有一个App Delegate对象(以及其他一些东西)。

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

右键单击它会显示一个HUD列表,您将在其中看到每个网点(以及其他信息)。找到 webber 网点,然后点击右侧的圆圈。然后将其拖到您的 WebView

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.

您刚刚完成的操作是将属性链接到XIB对象。跳过此步骤,您的应用程序代表将不知道 webber 指的是什么。

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.

另外,请注意为了填充该HUD列表,您的属性需要使用 IBOutlet 专门标记。

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

这篇关于可可的WebView在加载应用程序时不会加载URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆