我正在使用WKWebView和Swift語言創建一個簡單的Web查看器。這是我的代碼。獲取「線程1:EXC_BAD_ACCESS」錯誤?
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
}
}
我現在得到一個「主題1:EXC_BAD_ACCESS」在webView = WKWebView()
線錯誤,當我嘗試運行應用程序。我怎樣才能解決這個問題?
謝謝。我修改了我的代碼(請參閱上面的編輯代碼),但是我現在在初始化行上出現EXC_BAD_ACCESS錯誤? – user1741348 2014-10-08 18:36:00
@ user1741348嘗試 var webView = WKWebView(frame:CGRectMake(0,0,320,480)) – ytbryan 2014-10-08 23:12:48