![](/img/trans.png)
[英]How can I locate an NSBundle knowing its bundle-Identifier? (e.g. "com.apple.Preview")
[英]How can I display a website (e.g. apple) in a cocoa app using WebKit?
好的,到目前為止,我已經按照其他人的回答對整個事情進行了編碼,但是當我構建並運行項目時,我在代碼中指定的網站或html文件不會顯示在屏幕上; 僅顯示白屏。
到目前為止,這是我對頭文件所做的操作:
//MY HEADER FILE(.h):
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
@interface Project_XAppDelegate: NSObject <NSApplicationDelegate> {
NSWindow *window;
IBOutlet WebView *webView;
}
@property (assign) IBOutlet NSWindow *window;
@property (nonatomic, retain) IBOutlet WebView *webView;
@end
實現方式:
//MY IMPLEMENTATION FILE(.m):
#import "Project_XAppDelegate.h"
#import "WebKit/Webkit.h"
@implementation Project_XAppDelegate
@synthesize window;
@synthesize webView;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
}
- (void)awakeFromNib {
NSString *resourcesPath = [[NSBundle mainBundle] resourcePath];
NSString *htmlPath = [resourcesPath stringByAppendingString:@"/Users/*****/Desktop/Project X/HTML/mehmar.html"];
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]];
}
@end
您的htmlPath在我看來錯了。 對OSX的開發不太熟悉,但是一旦獲得了捆綁包路徑,就不應該只是將“ index.html”附加到其上,而不是將其完整路徑添加到磁盤上的文件中。
嘗試[resourcesPath stringByAppendingString:@"index.html"]
嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.