我刚开始开发 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 连接时,我无法在导出列表中找到“web View ”。 谢谢 我已经在上一篇文章之后更新了我的代码,但仍然无法正常工作。 再次感谢您的回复。
最佳答案
您需要添加 WebKit 框架。
#import <WebKit/WebKit.h>
关于objective-c - 如何在 WebView(OSX 项目)中启动时加载 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15921974/