Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iphone xcode项目中添加html页面?_Iphone_Html_Xcode - Fatal编程技术网

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

如何在iphone xcode项目中添加html页面?,iphone,html,xcode,Iphone,Html,Xcode,有人能告诉我如何在我的iphone项目中添加html吗?? 他们没有html选项,我点击在类组中添加新文件…为什么会这样?只需创建一个空白文件并将其重命名为html或将现有html文件添加到项目中。 下一步取决于您希望如何使用html文件 假设如果要加载名为page.html的本地文件,首先将该文件添加到project,然后在项目的构建阶段,将page.html添加到复制捆绑资源,并在应用程序中运行该操作,它会将该文件写入应用程序的文档字典/ NSString *Html = [[NSStrin

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

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

假设如果要加载名为page.html的本地文件,首先将该文件添加到project,然后在项目的构建阶段,将page.html添加到
复制捆绑资源
,并在应用程序中运行该操作,它会将该文件写入应用程序的
文档
字典/

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

完成了。

您可能要查找的是UIKit的UIWebView类的文档和示例代码。

您可以使用
UIWebView
这样显示html文件

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URLString]];
[webView loadRequest:request];

其中
URLString
包含的是您的文件url。

您应该接受其他问题的一些答案。我也想知道如何接受答案。嗨,我想知道如何使用html???我的意思是在iphone模拟器中显示html文件的内容。谢谢您想将本地html文件加载到UIWebView中吗?查看我的更新