gpt4 book ai didi

iphone - 如何在我的 iphone xcode 项目中添加 html 页面?

转载 作者:太空狗 更新时间:2023-10-29 15:47:27 25 4
gpt4 key购买 nike

谁能告诉我如何在我的 iphone 项目中添加 html?他们没有 html 选项,我点击在类组中添加新文件...这是为什么???

最佳答案

只需创建一个空白文件并将其重命名为 html 或将现有的 html 文件添加到项目中。下一步取决于您希望如何使用 html 文件。

如果你想加载一个名为 page.html 的本地文件,首先你将文件添加到项目中,然后在项目的构建阶段,将 page.html 添加到 Copy Bundle Resources ,并在您的应用程序中运行它,它将文件写入您应用程序的 documents 字典/

NSString *Html = [[NSString alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"page" ofType:@"html"] encoding:NSUTF8StringEncoding error:NULL];
[Html writeToFile:[[self docPath]stringByAppendingPathComponent:@"page.html"] atomically:YES encoding:NSUTF8StringEncoding error:NULL];
[Html release];

你的 webview 应该调用它来加载文件:

NSArray *docPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [docPaths objectAtIndex:0];
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[docPath stringByAppendingPathComponent:@"page.html"]]]];

完成了。

关于iphone - 如何在我的 iphone xcode 项目中添加 html 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5201997/

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