gpt4 book ai didi

xcode - Cocoa 的 WebView 在加载应用程序时不加载 URL

转载 作者:行者123 更新时间:2023-12-03 16:51:31 25 4
gpt4 key购买 nike

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

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

我必须在界面构建器中做什么?我已经添加了 Web View ,我需要以任何方式链接它吗?

事情是我添加了简单的文本字段(并将其链接到 WebView ),当我在那里输入时,它加载了 URL,但是它不包含此代码,有什么想法吗?

最佳答案

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

Objects

右键单击它应该会弹出一个 HUD 列表,您将在其中看到每个 socket (以及其他一些东西)。找到 webber socket ,然后单击圆圈以查看这是正确的。然后拖动到您的 WebView

Linking

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

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

关于xcode - Cocoa 的 WebView 在加载应用程序时不加载 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8319503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com