【问题标题】:How can I display a website (e.g. apple) in a cocoa app using WebKit?如何使用 WebKit 在可可应用程序中显示网站(例如苹果)?
【发布时间】:2011-03-28 21:01:04
【问题描述】:

好的,到目前为止,我已经按照其他人的答案编写了整个代码,但是当我构建和运行我的项目时,我在代码中指定的网站或 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

【问题讨论】:

    标签: macos webkit


    【解决方案1】:

    您的 htmlPath 在我看来是错误的。不太熟悉 OSX 开发,但是一旦您获得捆绑路径,您不应该只是将“index.html”附加到它而不是磁盘上文件的完整路径。

    试试[resourcesPath stringByAppendingString:@"index.html"]?

    【讨论】:

    • 感谢 Tejaswi 的建议,但我确实事先解决了;你知道如何显示网址吗?我的意思是显示网站的原理相同,但在这种情况下,将应用程序链接到网页,以便在访问时它是最新的。谢谢!
    猜你喜欢
    • 2021-11-11
    • 1970-01-01
    • 1970-01-01
    • 2021-08-25
    • 1970-01-01
    • 1970-01-01
    • 2016-08-23
    • 2010-11-28
    • 1970-01-01
    相关资源
    最近更新 更多