得到“线程1:EXC_BAD_ACCESS";错误? [英] Getting "Thread 1:EXC_BAD_ACCESS" error?
问题描述
我正在使用WKWebView和Swift语言创建一个简单的Web查看器.这是我的代码.
I am creating a simple web viewer using WKWebView and the Swift language. Here is my code.
import Cocoa
import WebKit
@NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet var containerView : NSView! = nil
@IBOutlet weak var window: NSWindow!
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
var webView: WKWebView
webView = WKWebView() //Thread 1:EXC_BAD_ACCESS (code=1,address=0x20)
var url = NSURL(string:"http://www.google.com/")
var req = NSURLRequest(URL: url!)
webView.loadRequest(req)
}
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
}
当我尝试运行应用程序时,在webView = WKWebView()
行上出现"Thread 1:EXC_BAD_ACCESS"错误.我该如何解决?
I'm now getting a "Thread 1:EXC_BAD_ACCESS" error on the webView = WKWebView()
line when I try to run the application. How can I fix this?
推荐答案
每当尝试使用全新的最小类作为委托时,都会出现此错误.例如:
I get this error whenever I try to use a brand new minimal class as a delegate. For example:
class MyDelegate: NSObject, UIWebViewDelegate { /* ... */ }
class MyDelegate: NSObject, UIWebViewDelegate { /* ... */ }
当我尝试使用默认的ViewController作为委托时,不会发生这种情况.例如:
This does not happen when I try to use the default ViewController as a delegate. For example:
class ViewController: UIViewController, UIWebViewDelegate { /* ... */ }
class ViewController: UIViewController, UIWebViewDelegate { /* ... */ }
我建议您使用ViewController作为委托,直到我们深入到此为止.
I would suggest using the ViewController as a delegate until we get to the bottom of this.
这篇关于得到“线程1:EXC_BAD_ACCESS";错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!