【发布时间】:2018-07-16 13:37:52
【问题描述】:
这是我的项目结构:
我有 2 个不同的视图控制器 (GameViewController, TaskViewController)。他们都应该能够向用户显示web view。
GameViewController 的Web 视图 应加载文件
www/game/index.htmlTaskViewController 的 Web 视图 应加载文件
www/task/index.html
添加网页视图非常简单。但是我怎样才能确定正确的路径呢?
这是我在GameViewController 中尝试过的:
let url = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "www/game") // not working
let url = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "game") // not working
let url = Bundle.main.url(forResource: "index", withExtension: "html", subdirectory: "myApplication/www/game") // not working
如何正确设置文件的路径(同名 [index.html] )?
任何帮助将不胜感激。谢谢。
【问题讨论】:
-
您必须将 HTML 文件作为“文件夹引用”添加到您的项目中,否则所有文件将被复制到应用程序包中的同一目录中。参见例如stackoverflow.com/questions/6420925/…。
标签: ios iphone swift webview uiviewcontroller