2012-12-29 55 views
2

我刚刚开始在Xcode,我试图制作一个OS X的Web浏览器。为什么webFrameLoadDelegate协议不起作用?

我想弄清楚我的webview何时加载以及何时不加载。我已经看了很多都从这里开始并在此Apple开发库页,这是我所得到的:

- (void)webViewDidStartLoad:(WebView *)webView { 
    //enter code here 
} 

当然,我也看到了webViewDidFinishLoadvoid,但是当我尝试这在我的AppDelegate.m没有任何反应。我已将webview的frameLoadDelegate连接到App Delegate,并且从我的理解中,我还需要在AppDelegate.h文件中使用<>协议。我的问题是,当我输入webFrameLoadDelegateProtocol<> s告诉我webFrameLoadDelegateProtocol不存在。

回答

4

我的问题是,当我输入“webFrameLoadDelegateProtocol”变成了“<>” S它告诉我,“webFrameLoadDelegateProtocol”不存在。

WebFrameLoadDelegate Protocolinformal protocol。它没有资格以相同的方式通过。从班级的@interface中省略<webFrameLoadDelegateProtocol>

当我尝试在我的AppDelegate.m中没有任何反应。我已连接的WebView frameLoadDelegate到App代表

当你设置Web视图的frameLoadDelegate属性为您的应用程序代理?

+0

然后我用哪个协议访问webview的加载? – biffletsbq

+0

使用非正式协议。您不需要(也不能)将您的类声明为采用WebFrameLoadDelegateProtocol。 –

+0

@ user1936689查看我的编辑。这听起来像你可能没有正确设置你的web视图的frameLoadDelegate属性...... –

10

这似乎是因为你还没有设置webView委托。你不需要将协议添加到你的头部。相反,您需要在某处添加此代码,我建议在applicationDidFinishLaunching

[webView setFrameLoadDelegate:self]; 

然后您可以重写这些方法。如果这不起作用,那么请确保您已将您的webView从标题连接到IB中的webView。另外请确保在.m中合成webView。

最后,您可以将我的开源示例用于OS X浏览器。它是在MIT的许可下,所以你可以自由使用它。

https://github.com/JosiahOne/basic_cocoa_web_browser

编辑

我才意识到,你正在使用可可错误的方法。改用这些方法。

-(void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame 
{ 
    //Did start Load 
} 

-(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame 
{ 
    //Did finish Load 
} 
+0

我用我的webview的名称替换“webView”? – biffletsbq

+0

只有这部分:[webView setFrameLoadDelegate:self]。我相信这个方法很好。 – Josiah

+0

谢谢。这非常有帮助。 – biffletsbq