简体   繁体   中英

Implementing delegate methods, but still getting a warning?

I'm getting a peculiar warning, specifically this one:

warning: class does not implement the 'UIWebViewDelegate' protocol

... when I have these methods in my application:

-(void)webViewDidStartLoad {
    ...
}

-(void)webViewDidFinishLoad {
    ...
}

... and even after setting the UIWebView's delegate to self , I still get this warning, and the methods are never called ( NSLog provides no results.)

Can anyone pinpoint what is happening here? Thanks in advance!

I don't think your delegate methods are correct. Shouldn't they be:

- (void)webViewDidStartLoad:(UIWebView *)webView
{
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
}

As '@No on in particular' says, your methods aren't declared correctly. That is why the methods aren't called at all.

The warning has a different reason. It is because your interface definition doesn't declare that it implements the UIWebViewDelegate protocol.

@interface MyClass : NSObject <UIWebViewDelegate> {
...
}
...
@end

Whether or not the interface declares the protocol or not is actually of no consequence at runtime, it is just a hint to the compiler that allows it to issue warnings like the one you are seeing, or warnings if you don't implement the methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM