2

I am just starting out at Xcode, and I'm trying to make a OS X web browser.

I want to figure out when my webview is loading and when it isn't. I've already looked at a lot of pages both from here and the Apple Developer Library on this, and this is what I get:

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

And of course I also saw the webViewDidFinishLoad void, but when I try this in my AppDelegate.m nothing happens. I have connected the webview's frameLoadDelegate to the App Delegate and from what I understand, I also need to use the <> protocols in the AppDelegate.h file. My problem is that when I type in webFrameLoadDelegateProtocol into the <>s it tell me that webFrameLoadDelegateProtocol doesn't exist.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
ccbreen
  • 247
  • 3
  • 11

2 Answers2

10

It appears to be because you haven't set the webView delegate. You do not need to add the protocol to your header though. Instead you need to add this code somewhere, I suggest in applicationDidFinishLaunching

[webView setFrameLoadDelegate:self];

Then you can override the methods. If that doesn't work, then make sure you have connected your webView from the header to the webView in your IB. Also be sure to synthesize the webView in the .m.

Finally, you could use my open source example for an OS X browser. It is under the MIT license, so you can use it freely.

https://github.com/JosiahOne/basic_cocoa_web_browser

EDIT

I just realized, you are using the wrong method for Cocoa. Use these methods instead.

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

-(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
    //Did finish Load
}
Josiah
  • 4,663
  • 2
  • 31
  • 49
4

My problem is that when I type in "webFrameLoadDelegateProtocol" into the "<>"s it tell me that "webFrameLoadDelegateProtocol" doesn't exist.

WebFrameLoadDelegate Protocol is an informal protocol. It is not eligible for adoption in the same way. Omit <webFrameLoadDelegateProtocol> from your class's @interface.

when I try this in my AppDelegate.m nothing happens. I have connected the webview's frameLoadDelegate to the App Delegate

When do you set the web view's frameLoadDelegate property to be your app delegate?

Community
  • 1
  • 1
Nate Chandler
  • 4,533
  • 1
  • 23
  • 32
  • Then which protocol do I use to access the webview's loading? – ccbreen Dec 29 '12 at 19:30
  • Use the informal protocol. You just don't need to (and can't) declare your class as adopting WebFrameLoadDelegateProtocol. – Nate Chandler Dec 29 '12 at 19:36
  • @user1936689 Check out my edit. It sounds like you may not be setting up your web view's `frameLoadDelegate` property properly... – Nate Chandler Dec 29 '12 at 19:51
  • No I just dragged the frameLoadDelegate outlet of my webview to the App Delegate – ccbreen Dec 29 '12 at 19:52
  • my problem is when I try to set the protocol of AppDelegate.h to "" like the Apple Developer Library said – ccbreen Dec 29 '12 at 19:54
  • As I said, you cannot do that. Adopting an informal protocol has a different meaning from adopting a formal protocol. In particular, `` only works if `ProtocolName` is a formal protocol. – Nate Chandler Dec 29 '12 at 19:56
  • Ok. So then is there a formal protocol I could use? – ccbreen Dec 29 '12 at 20:02
  • You will not need to declare your app delegate to be adopting any protocol. If your app delegate is set to be your web view's `frameLoadDelegate`, and your web view starts loading, your app delegate (as long as it implements `-webViewDidStartLoad:`) will have `-webViewDidStartLoad:` called on it. If this is not happening, there is another problem. – Nate Chandler Dec 29 '12 at 20:04
  • so what exactly would I type? – ccbreen Dec 29 '12 at 20:11
  • #import <"WebKit/WebKit.h"> – ccbreen Dec 29 '12 at 20:12
  • @interface AppDelegate : NSObject { – ccbreen Dec 29 '12 at 20:12
  • @user1936689, I see your problem. You are using the wrong messages. See my answer. – Josiah Dec 29 '12 at 20:12
  • it says it can't find the decaration for frameLoadDelegate – ccbreen Dec 29 '12 at 20:13
  • @user1936689 You don't need to declare AppDelegate as adopting any protocol related to the web view. replace the line you pasted with `@interface AppDelegate : NSObject {`. – Nate Chandler Dec 29 '12 at 20:13
  • @AceLegend is right. You're using the wrong informal protocol methods. A revision, then, of my previous comment: If your app delegate is set to be your web view's frameLoadDelegate, and your web view starts loading (via `[[theWebView mainFrame] loadRequest:theRequest]`), your app delegate (as long as it implements `-webView:didStartProvisionalLoadForFrame:`) will have `-webView:didStartProvisionalLoadForFrame:` called on it. If this is not happening, there is another problem. – Nate Chandler Dec 29 '12 at 20:17
  • 1
    Actually I use [theWebView setMainFrameURL:theRequest] – ccbreen Dec 29 '12 at 20:19