Question

I think implement completely same method to every viewController with UIWebView (and delegate=self)is not smart. So tried to setup common loading method with all UIWebView. But it did not work. Is it wrong to achieve with category?

UIWebView+Loading.m

-(void)webViewDidStartLoad:(UIWebView*)webView
{ 
   [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}

ViewController.h

@interface ViewController : UIViewController <UIWebViewDelegate>

ViewController.m

#import "UIWebView+Loading.h"

//abbr...

-(void)viewWillAppear:(BOOL)animated
{
    UIWebView *someWebView = [[UIWebView alloc] init];
    someWebView.delegate = self;

    //and HTTP request
    NSURLRequest *req = (abbr);
    [someWebView loadRequest:req];
}
Was it helpful?

Solution

The method webViewDidStartLoad: is not being called because it is a part of UIWebViewDelegate protocol, not a method of UIWebView class itself. You have to implement it in your ViewController.m file.

Also, you may want to read about delegation pattern in iOS.

OTHER TIPS

Dont need a category like UIWebView+Loading.m for this purpose.

The webview delegate methods will get executed when the loading stats and the delegate method

- (void)webViewDidStartLoad:(UIWebView *)webView {
    NSLog(@"Started loading");
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    NSLog(@"Finshed loading");
}

will get executed.The code you written is enough.Since the delegate is set to self .In the viewcontroller define these methods and thats it .You will have it working

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top