开发者

Implementing delegate methods, but still getting a warning?

开发者 https://www.devze.com 2023-01-17 01:35 出处:网络
I\'m getting a peculiar warning, specifically this one: warning: class does not implement the \'UIWebViewDelegate\' protocol

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)webViewD开发者_运维问答idFinishLoad {
    ...
}

... 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!


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.


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

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

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

精彩评论

暂无评论...
验证码 换一张
取 消