gpt4 book ai didi

objective-c - OS X Web View 应用程序 - 不会加载本地 .html 网页

转载 作者:行者123 更新时间:2023-12-03 16:58:01 37 4
gpt4 key购买 nike

我的 AppDelegate.m 文件中有以下代码,当我打开应用程序时,该文件会打开 Google。我试图更改它以打开我复制到 Xcode 项目中的 .HTML 网页,但它不起作用。我使用的是 Xcode 4.5.2。

用于打开 Google 的代码是:

@implementation MDAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
[self.webView.mainFrame loadRequest:request];
}

我尝试将其更改为(以便它加载我放入项目文件夹中的 test.html 文件,但应用程序现在显示为空白)。我错过了什么?

@implementation MDAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"test.html"]];
[self.webView.mainFrame loadRequest:request];
}

最佳答案

只要将您的 test.html 复制到项目的根目录(确保它也复制到您的最终应用程序包,嗯? - 检查构建阶段 )您可以使用以下代码将其加载到您的 Web View 中:

NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];
NSURL* fileURL = [NSURL fileURLWithPath:path];
NSURLRequest* request = [NSURLRequest requestWithURL:fileURL];
[self.webView.mainFrame loadRequest:request];

关于objective-c - OS X Web View 应用程序 - 不会加载本地 .html 网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14823955/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com