【发布时间】:2014-08-28 11:25:56
【问题描述】:
我有一个基本的 Cocoa 应用程序,它的窗口中只有一个 WebView。 WebKit.framework 引用已添加到 OS X 10.9(小牛队)上的 Xcode 6 beta 6 项目中。我想知道WebView 何时完成加载页面。所以我创建了一个WebViewControllerDelegate 类继承WebFrameLoadDelegate。这已经是问题开始的地方:Xcode 告诉我Use of undeclared type 'WebFrameLoadDelegate'。关于this question on Stack Overflow,不应该。如前所述,WebKit.framework 被项目引用,WebKit 模块被导入到 Swift 类文件中。我还在Xcode左侧栏中的“Headers”文件夹中看到WebFrameLoadDelegate.h,在WebKit.framework下方。
万恶之源是TestWebView/WebViewControllerDelegate.swift文件中的11行(我忘了删除这里省略的cmets),类声明和协议引用。
import WebKit
class WebViewControllerDelegate: WebFrameLoadDelegate {
func didFinishLoadForFrame() {
NSLog("didFinishLoadForFrame()")
}
}
AppDelegate,设置一切:
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?) {}
}
如需更多信息,请查看我为这个问题创建的my public repository 中的代码。
【问题讨论】:
标签: xcode macos webview swift webkit