How to properly use the webkit delegate to start and stop the counter, OS X, OBJ-C

It seems like it should be that simple, but I'm pretty new to Objective-C. What I want to do is just start and stop the counter while my WebView loads. This is an OS X application. All I was looking for is for Cocoa Touch, I only use Cocoa. In my AppDelegate.m I have methods that start and stop the counter (this works, I tested it).

-(IBAction)goSpin:(id)sender { [spinner startAnimation:self]; } -(IBAction)stopSpin:(id)sender { [spinner stopAnimation:self]; } 

I also have two delegate methods for webView that I redefined.

 -(void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame { [self goSpin:self]; } -(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { [self stopSpin:self]; } 

Basically, I would like to know how I can get a webView to set its delegate. Usually I have to do something in the .h file, but I cannot find links that list what the webKit delegate will do. Any help would be greatly appreciated.

+4
source share
2 answers

 -(void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame 

and

 -(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame 

are part of the WebFrameLoadDelegate protocol .

WebView has a frameLoadDelegate property. Install it in your WebView instance by calling [webView setFrameLoadDelegate:delegate] , where delegate is an NSObject that implements two methods (it will be easier for you to make self frameLoadDelegate here). Since WebFrameLoadDelegate is an unofficial protocol, delegate must declare two methods in its .h file, and not add <WebFrameLoadDelegate> to its class declaration, as with the formal protocol.

+9
source

You can override these webview delegate methods to start and stop the counter.

 - (void)webViewDidStartLoad:(UIWebView *)webView{ // In this method you have to start a spinner. } - (void)webViewDidFinishLoad:(UIWebView *)webView{ // In this method you have to stop the current spinner. } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ // In this method you have to stop the current spinner. } 
-3
source

Source: https://habr.com/ru/post/1437276/


All Articles