作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
谁能告诉我如何在我的 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/
我是一名优秀的程序员,十分优秀!