簡體   English   中英

Bundle.main.url(forResource:“ hello”,withExtension:“ html”)返回nil

[英]Bundle.main.url(forResource: “hello”, withExtension: “html”) is returning nil

我創建了hello.html文件。嘗試訪問該文件時,url每次都返回nil。

  override func viewDidLoad() {
        super.viewDidLoad()
        if let url = Bundle.main.url(forResource: "hello", withExtension: "html"){
            if let htmlData = try? Data(contentsOf:url){
                let baseURL = URL(fileURLWithPath: Bundle.main.bundlePath)
                webView.load(htmlData, mimeType: "text/html", textEncodingName: "UTF-8", baseURL: baseURL)

            }
        }

        // Do any additional setup after loading the view.
    }

在此處輸入圖片說明

  1. 將hello.html放到您的項目中
  2. 如果需要,請單擊復制項目
  3. 添加到目標項目
  4. 沒關系

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM