xcode - 当用户在 webkit 中没有互联网连接时加载新 View

标签 xcode swift webkit

我有一个正在 Webkit 中加载的网络应用程序,截至目前,当用户没有互联网连接时,会显示一条错误消息和此代码。我想让它显示一个全新的 View ,而不仅仅是一条错误消息。

func webView(webView: WKWebView!, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError!) {
    let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .Alert)
    alert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil))
    presentViewController(alert, animated: true, completion: nil)        
}

最佳答案

您可以创建一个新的 UIView 并将其添加到当前的 ViewController 中:

var errorView = UIView(frame: CGRectMake(100, 100, 100, 100))

self.view.addSubview(errorView)

关于xcode - 当用户在 webkit 中没有互联网连接时加载新 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28682382/

相关文章:

ios - 部署后向 App-Info.plist 添加值

ios - 引用 socket 未显示在 xcode 6 中

ios - 展开后,在 Xcode 中取消 View 修改

swift - 在函数签名中指定模式时,临时多态性/函数重载在 Swift 中不起作用

swift - 在 Swift 4 中使用reduce 连接数组和条件

ios - 如何映射一个我不知道参数个数的json

ruby-on-rails - capybara + Webkit : How to test client side validations - "required" input elements?

xcode - 在 Xcode4 项目中包含 C 工具

css - 如何在 Safari 中显示一种样式而在 Chrome 中显示另一种样式?

javascript - 帮助在 UIWebView 中使用 Javascript 代码