Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 可可错误嘟嘟声|性能等效_Cocoa_Beep - Fatal编程技术网

Cocoa 可可错误嘟嘟声|性能等效

Cocoa 可可错误嘟嘟声|性能等效,cocoa,beep,Cocoa,Beep,我有一个Cocoa/swift应用程序,它使用WKWebView创建了一个最小的web视图,请参见下面的代码 当我运行应用程序时,当前www.google.com上的示例网页加载正确,但是如果我尝试使用keypup和keypdown方法,或者尝试复制和粘贴文本,我会收到系统错误声音/ding/beep 因此,我创建了一个performKeyEquivalent函数: func performKeyEquivalent(theEvent: NSEvent) -> Bool { ret

我有一个Cocoa/swift应用程序,它使用WKWebView创建了一个最小的web视图,请参见下面的代码

当我运行应用程序时,当前www.google.com上的示例网页加载正确,但是如果我尝试使用keypup和keypdown方法,或者尝试复制和粘贴文本,我会收到系统错误声音/ding/beep

因此,我创建了一个performKeyEquivalent函数:

func performKeyEquivalent(theEvent: NSEvent) -> Bool {
    return true
}
但是我认为我没有正确地实施它。我不熟悉xcode和swift

请参阅下面的完整代码。任何帮助都将不胜感激

import Cocoa import WebKit import AppKit

@NSApplicationMain

class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var window: NSWindow!
    @IBOutlet weak var customView: NSView!

    func applicationDidFinishLaunching(aNotification: NSNotification) {
        // Insert code here to initialize your application
        var url = NSURL(string:"http://www.google.com/")
        var request = NSURLRequest(URL:url!)
        var theWebView:WKWebView = WKWebView(frame: customView.bounds)
        customView.addSubview(theWebView)
        theWebView.autoresizingMask = NSAutoresizingMaskOptions.ViewWidthSizable | NSAutoresizingMaskOptions.ViewHeightSizable   
        theWebView.loadRequest(request)
    }

    func performKeyEquivalent(theEvent: NSEvent) -> Bool {
        return true
    }

    func applicationWillTerminate(aNotification: NSNotification) {
        // Insert code here to tear down your application
    }
}

我浪费了大约一个小时试图找到您问题的解决方案,但我遇到了与您在中遇到的相同的崩溃,当时我只是尝试使用上述代码以编程方式在Swift中创建WKWebView。你是怎么解决的?同时,我建议您创建一个NSWindowController,并将您的WKWebView代码移到那里。在之前发布的代码中,我从未解决过EXC_BAD_ACCESS崩溃问题,但我确实找到了另一个解决方案,我对该解决方案进行了轻微修改以处理Cocoa。我不熟悉Xcode和swift,如何创建NSWindowController?您有没有想过如何消除错误提示?我也有同样的问题。