我刚刚开始开发 Mac 应用程序,我希望在应用程序启动时 WebView 是一个 URL。这是我的代码:
AppDelegate.h
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
@interface AppDelegate : NSObject <NSApplicationDelegate> {
WebView *myWebView;
//other instance variables
}
@property
(retain, nonatomic) IBOutlet WebView *myWebView;
//other properties and methods
@end
AppDelegate.m:
#import "AppDelegate.h"
#import <WebKit/WebKit.h>
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString *urlText = @"http://google.com";
[[self.myWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
return;
// Insert code here to initialize your application
}
@end
如何在 WebView(OSX 项目)中启动时加载 URL?
我认为代码可以工作,但是当我尝试将代码与 Interface Builder 中的 WebView 连接时,我在插座列表中找不到“网络视图”。谢谢我在上一篇文章之后更新了我的代码,但仍然无法正常工作。再次感谢您的回复。