2013-01-15 21 views
0

我在這裏看到,許多人使用此代碼,但與我一起工作。好。 (桌面應用程序)如何在Xcode中使用Web視圖啓動頁面?

簡單的WebView汽車laucher URL

我會一步

1交談步)創建一個項目

2)創建一個窗口和一個Web視圖

3)把標識符如何prevelwindow(網絡視圖)和窗口(窗口)

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)好了,然後我編譯它,它不工作。

+0

錯誤您從編譯器得到什麼? – Jules

+1

另外,我有一個開源的應用程序,你可以下載參考。 https://sites.google.com/site/infiniteopensyntax/basic-web-browser – Josiah

+0

嘗試用我的指示創建一個新項目(請參閱下面的答案)。您目前的項目可能有問題。 –

回答

1

首先,您必須添加WebKit.frameworkTargets->Build Phases->Link Binary)。

然後你就可以在你的.h AppDelegate文件#import,並宣佈了新的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 ,並將其連接到您的.nib文件中的MyWebViewIBOutlet

WebViewAdd a new WebView

連接IBOutletOutletsTheWebObj

+0

錯誤:(沒有已知的類選擇器'mainFrame'的方法 –

+0

感謝所有,我從josiah e下載項目opensource !!謝謝! –

相關問題