gpt4 book ai didi

ios - 出现 "Thread 1:EXC_BAD_ACCESS"错误?

转载 作者:搜寻专家 更新时间:2023-11-01 05:42:54 30 4
gpt4 key购买 nike

我正在使用 WKWebView 和 Swift 语言创建一个简单的网络查看器。这是我的代码。

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”错误。我该如何解决这个问题?

最佳答案

如果这就是您的全部代码,那么我会说您缺少实例化 WKWebView。在 self.webView!.loadRequest(req) 行打断点,判断是否为 nil。

我从未使用过WKWebView,但我认为您需要一个 View Controller 。也许这篇博文可以帮助您:Getting started with WKWebView using Swift in iOS 8

关于ios - 出现 "Thread 1:EXC_BAD_ACCESS"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26253005/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com