0

ここでは、多くの人がこのコードを使用していますが、私と一緒に作業しています。上手。(デスクトップアプリ)

シンプルなwebview自動ラウチャーURL

少しずつ話をしに行きます

1)プロジェクトを作成する

2)ウィンドウとWebビューを作成します

3)prevelwindow(Webビュー)とwindows(ウィンドウ)の識別子を入力します

4)私の.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)私の.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)それでは、コンパイルしましたが、機能していません。

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新しいWebViewを追加します

を接続しますIBOutletアウトレットTheWebObj

于 2013-01-15T21:27:11.627 に答える