为什么将WebFrameLoadDelegate视为未声明? [英] Why is WebFrameLoadDelegate considered as undeclared?

查看:135
本文介绍了为什么将WebFrameLoadDelegate视为未声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的Cocoa应用程序,其窗口中只有一个WebView. WebKit.framework参考已添加到OS X 10.9 (Mavericks)上的Xcode 6 beta 6 项目中.我想知道WebView何时加载页面.因此,我创建了一个继承WebFrameLoadDelegateWebViewControllerDelegate类.问题已经开始出现了:Xcode告诉我有关Use of undeclared type 'WebFrameLoadDelegate'的信息.关于关于堆栈溢出的问题,应该不会.如前所述,项目引用了WebKit.framework并将其导入了Swift类文件中的WebKit模块.我还在Xcode左侧栏中的WebKit.framework下方看到了WebFrameLoadDelegate.h.

I have a basic Cocoa application having only a WebView in its window. The WebKit.framework reference is added to the Xcode 6 beta 6 project on OS X 10.9 (Mavericks). I would like to know when the WebView finished loading a page. So I created a WebViewControllerDelegate class inheriting WebFrameLoadDelegate. That already is the place where the problems start: Xcode tells me about Use of undeclared type 'WebFrameLoadDelegate'. Relating to this question on Stack Overflow, it should not. Like already mentioned, the WebKit.framework is referenced by the project and the WebKit module imported in the Swift class file. I also see the WebFrameLoadDelegate.h in the "Headers" folder in the left side bar of Xcode, underneath the WebKit.framework.

万恶之源是文件TestWebView/WebViewControllerDelegate.swift中的行11(我忘记删除此处省略的注释),类声明和协议引用.

The root of all evil is line 11 in file TestWebView/WebViewControllerDelegate.swift (I forgot to remove the comments which I omitted here), the class declaration and protocol reference.

import WebKit

class WebViewControllerDelegate: WebFrameLoadDelegate {
    func didFinishLoadForFrame() {
        NSLog("didFinishLoadForFrame()")
    }
}

AppDelegate,它完成了所有设置:

The AppDelegate, which sets everything up:

import Cocoa
import WebKit

class AppDelegate: NSObject, NSApplicationDelegate {
    @IBOutlet weak var window: NSWindow!
    @IBOutlet weak var webView: WebView!
    @IBOutlet weak var webViewControllerDelegate: WebViewControllerDelegate!

    func applicationDidFinishLaunching(aNotification: NSNotification?) {
        self.webView.frameLoadDelegate = self.webViewControllerDelegate
        self.webView.mainFrame.loadRequest(NSURLRequest(URL: NSURL(string: "https://stackoverflow.com/")))
    }

    func applicationWillTerminate(aNotification: NSNotification?) {}
}

有关更多信息,请查看我创建的我的公共存储库中的代码这个问题.

For further information, please take a look at the code in my my public repository which I created for this question.

推荐答案

WebFrameLoadDelegate是非正式协议,因此您不能声明其符合性.只需继承NSObject并实现所需的方法即可.

WebFrameLoadDelegate is an informal protocol, so you can't declare conformance to it. Just inherit from NSObject and implement the desired methods.

此外,请注意,Swift方法的名称是webView(sender: WebView!, didFinishLoadForFrame frame: WebFrame!),而不仅仅是didFinishLoadForFrame().

Also, note that the Swift method name is webView(sender: WebView!, didFinishLoadForFrame frame: WebFrame!), not just didFinishLoadForFrame().

class WebViewControllerDelegate: NSObject { // WebFrameLoadDelegate
      override func webView(sender: WebView!, didFinishLoadForFrame frame: WebFrame!) {
      NSLog("didFinishLoadForFrame()")
    }
}

这篇关于为什么将WebFrameLoadDelegate视为未声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆