Getting “Thread 1:EXC_BAD_ACCESS” error?

偶尔善良 提交于 2019-12-06 07:23:06

If that's it's all your code, than I'd say you're missing to instantiate the WKWebView. Put a breakpoint on the self.webView!.loadRequest(req) line and check whether it's nil or not.

I've never worked with WKWebView, but I think that you need a view controller. Maybe this blog post can help you: Getting started with WKWebView using Swift in iOS 8

You forgot to initialise your WKWebView

var webView = WKWebView(frame: CGRectMake(0, 0, 320, 480))
var url = NSURL(string:"http://www.google.com/")
var req = NSURLRequest(URL: url)
webView.loadRequest(req)

I get this error whenever I try to use a brand new minimal class as a delegate. For example:

class MyDelegate: NSObject, UIWebViewDelegate { /* ... */ }

This does not happen when I try to use the default ViewController as a delegate. For example:

class ViewController: UIViewController, UIWebViewDelegate { /* ... */ }

I would suggest using the ViewController as a delegate until we get to the bottom of this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!