UIWebView 显示本地加载图像的白屏

UIWebView displaying white screen for locally loaded images

我正在使用 Swift 编写我的第一个 iOS 应用程序(仅适用于 iPad),其中,应用程序将根据应用程序上存在的资源加载 html,并且用户 selected.I 的值正在使用以下函数在 UIWebView 上加载数据。所有资源都存在于项目中。

        let url =  NSBundle.mainBundle().URLForResource(updatedResource, withExtension: "html")
        let requestObj = NSURLRequest(URL: url!);
        htmlWebView.loadRequest(requestObj);

url为需要加载的资源名称

print("This is the request \(htmlWebView.request)") 给我的价值是

This is the request Optional(<NSMutableURLRequest: 0x7fc180589a00> { URL: file:///Users/ios/Library/Developer/CoreSimulator/Devices/CB5ACC92-856E-4CBE-B4D4-03B0C1774765/data/Containers/Bundle/Application/C588D7E2-15F0-406A-8B09-227E2284459E/DemoHTML5.app/file3.html })

之前,我在 iPad 迷你模拟器上部署了该应用程序,但是在 iPad 2/iPad 空中模拟器

上部署时显示白屏

P.S : 我正在使用 XCode 6.1 和 运行 iOS 8.1 上的应用程序(OS 10.11 升级正在进行中)。所有资源都在应用程序中

这段代码对我来说很好用。我猜你的故事板在 iPad 上有问题。这是一个演示解决方案的示例项目:

https://www.dropbox.com/s/0xekspq2otqoq3l/SimpleWebViewLoader.zip?dl=0

里面的代码很简单:

class ViewController: UIViewController {
    @IBOutlet weak var webView: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let url =  NSBundle.mainBundle().URLForResource("test", withExtension: "html")
        let requestObj = NSURLRequest(URL: url!)
        webView.loadRequest(requestObj) 
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

我包含了 zip,因此您可以 运行 它并查看它是否对您有不同的作用。注意我使用的是 Xcode 7.3。通常建议您查看 Xcode 版本的最新信息。