0

I see here that many using this code but do working with me. Well. (DESKTOP APP)

Simple webview auto laucher URL

I will go to talk step by step

1) Create a project

2) Create a window and a web view

3) Put the identifier how prevelwindow (web view) and windows (window)

4) In My .H

#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>

@interface AppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;
WebView *prevelwindow;
}

@property (strong) IBOutlet NSWindow *window;
@property (strong) IBOutlet WebView *prevelwindow;
@end

5) In My .M

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window;

@synthesize prevelwindow;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSString *urlString = @"http://www.google.com.br";

[[prevelwindow mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL             URLWithString:urlString]]];
}

@end

6) Well then I compile it and it is not working.

4

1 回答 1

1

首先,您必须添加WebKit.framework( Targets->Build Phases->Link Binary)。

然后你可以#import在你的.h AppDelegate文件中声明一个新的WebView

#import "WebKit/WebKit.h"

@interface Check_AccountzAppDelegate : NSObject <NSApplicationDelegate> {
    WebView *MyWebView;
}

@property (retain, nonatomic) IBOutlet WebView *MyWebView;

现在您可以加载一个新的请求(.m AppDelegate文件):

@synthesize MyWebView;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    [[MyWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
}

最后添加一个 WebView,并将其连接到您MyWebView IBOutlet.nib文件中:

WebView添加新的 Web 视图

连接IBOutlet奥特莱斯网络对象

于 2013-01-15T21:27:11.627 回答