我如何在我的iphone

我如何在我的iphone

本文介绍了我如何在我的iphone xcode项目中添加html页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

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



如果要加载名为page.html的本地文件,请先添加要投影的文件,在项目的构建阶段,以及page.html到 Copy Bundle Resources ,然后在您的应用程序中运行它,它将文件写入到 documents 应用程序的字典/

  NSString * Html = [[NSString分配] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@pageofType:@html] encoding:NSUTF8StringEncoding error:NULL]; 
[Html writeToFile:[[self docPath] stringByAppendingPathComponent:@page.html] atomically:YES encoding:NSUTF8StringEncoding error:NULL];
[Html发布];

并且您的webview应该调用它来加载文件:

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

完成了。


can anyone tell how to add html in my iphone project??And their is no html option which i click on add new file in class group...why is that???

解决方案

simply create a blank file and rename it to html or add existing html file to the project.the next step depends on how you wish to use the html file.

Say if you want to load a local file called page.html, first you add the file to project,and in the build phases of your project, and the page.html to Copy Bundle Resources, and run this in your app, it writes the file to the documents dictionary of your app/

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];

and your webview should call this to load the file:

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

and it's done.

这篇关于我如何在我的iphone xcode项目中添加html页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 09:37