Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.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
Html uiwebview或读取css文件或图像_Html_Ios_Css_Uiwebview - Fatal编程技术网

Html uiwebview或读取css文件或图像

Html uiwebview或读取css文件或图像,html,ios,css,uiwebview,Html,Ios,Css,Uiwebview,我有一个成功显示本地html文件的web视图。css文件和imgage与html文件和应用程序文件位于同一文件夹中。 我尝试了三种不同的方法来显示html,但没有一种显示css或图像。图像由一个带问号的小正方形表示 这是加载函数 func loadPage() { // 1st try // if let htmlFile = NSBundle.mainBundle().pathForResource(page, ofType: "html"){ //let htmlData = NSData(

我有一个成功显示本地html文件的web视图。css文件和imgage与html文件和应用程序文件位于同一文件夹中。 我尝试了三种不同的方法来显示html,但没有一种显示css或图像。图像由一个带问号的小正方形表示

这是加载函数

func loadPage() {
// 1st try
// if let htmlFile = NSBundle.mainBundle().pathForResource(page, ofType: "html"){
//let htmlData = NSData(contentsOfFile: htmlFile)
//let baseURL = NSURL.fileURLWithPath(NSBundle.mainBundle().bundlePath)

// webView.loadData(htmlData, MIMEType: "text/html", textEncodingName: "UTF-8", baseURL: baseURL)

// 2nd try - - - - - - -
//  let localfilePath = NSBundle.mainBundle().URLForResource(page, withExtension: "html");
//let myRequest = NSURLRequest(URL: localfilePath!);
//webView.loadRequest(myRequest);

var testHTML = NSBundle.mainBundle().pathForResource(page, ofType: "html")
var contents = NSString(contentsOfFile: testHTML!, encoding: NSUTF8StringEncoding, error: nil)
var baseUrl = NSURL(fileURLWithPath: testHTML!) //for load css file

webView.loadHTMLString(contents, baseURL: baseUrl)



//}
}
html是

<meta charset="utf-8">
<link rel="stylesheet" href="bg.css" type="text/css">


<h1>1 ornano car park</h1>
<p class= "test"> At the end of the coach park there's a circle where coaches can turn. From there turn your back on the cathedral and go towards the river.</p>
<img src="board.jpg">
哪张照片

   Optional("/Users/colinmcgarry/Library/Developer/CoreSimulator/Devices/7BAEC0D1-5942-4D60-AD4F-CCFF4C70BB0B/data/Containers/Bundle/Application/42AAF91D-8477-428A-AEC6-950D89846C80/TestWebView2.app/1page.html")
nil
该bg.css文件与html文件位于同一文件夹中,并且位于应用程序中的文件列表中。xcode似乎不存在。

找到了解决方案。 我一直在用靶子做实验。这些文件不在活动目标中。 打印路径使我意识到我将TestWebView2作为目标。
保持头脑清醒。

奇怪的是,你的问题通过正确、简洁地描述需要发生的一切来提供答案。谢谢:)
   Optional("/Users/colinmcgarry/Library/Developer/CoreSimulator/Devices/7BAEC0D1-5942-4D60-AD4F-CCFF4C70BB0B/data/Containers/Bundle/Application/42AAF91D-8477-428A-AEC6-950D89846C80/TestWebView2.app/1page.html")
nil