Cocoa 如何在打开应用程序时启动网页
大家好,我需要帮助。我正在尝试在Xcode 4.0中为mac制作一个应用程序,我希望它在发布时显示一个网页。我已经添加了webkit框架,并获得了一些代码,但它不起作用。代码如下 app delegate.m文件Cocoa 如何在打开应用程序时启动网页,cocoa,Cocoa,大家好,我需要帮助。我正在尝试在Xcode 4.0中为mac制作一个应用程序,我希望它在发布时显示一个网页。我已经添加了webkit框架,并获得了一些代码,但它不起作用。代码如下 app delegate.m文件 #import "AppDelegate.h" #import <WebKit/WebKit.h> @implementation AppDelegate @synthesize window = _window; @synthesize WebView; -
#import "AppDelegate.h"
#import <WebKit/WebKit.h>
@implementation AppDelegate
@synthesize window = _window;
@synthesize WebView;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString *urlAddress = @"http://www.google.com/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[[WebView mainFrame] LoadRequest:requestObj];
}
@end
和app delegate.h文件
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet WebView *WebView;
@interface myAppDelegate : NSObject <NSApplicationDelegate> {
WebView *myWebView;
}
@property (retain, nonatomic) IBOutlet WebView *myWebView;
@end
如果有人能帮忙,请尽快回复谢谢大家 嗯,我假设代码没有编译?不应该这样。.h应该看起来像:
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
@interface AppDelegate : NSObject <NSApplicationDelegate> {
WebView *_myWebView; // not needed if you're using the latest xcode
}
@property (assign) IBOutlet NSWindow *window;
@property (retain, nonatomic) IBOutlet WebView *myWebView;
@end
m:
#import "AppDelegate.h"
#import <WebKit/WebKit.h>
@implementation AppDelegate
@synthesize window = _window;
@synthesize myWebView = _myWebView;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString *urlAddress = @"http://www.google.com/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[[self.myWebView mainFrame] loadRequest:requestObj]; // note the lower case 'l' in 'loadRequest'
}
@end
这假设您已将.xib中的webview与myWebView属性连接起来。谢谢您修复了它。另一个原因是我忘了将web视图与myWebView属性连接起来