Sending Class to Parameter of Incompatible Type 'id<UIWebViewDelegate>' Warning?

烈酒焚心 提交于 2020-01-01 09:39:30

问题


I wasn't expecting my program to put up a fuss when I wrote this line of code:

[twitterFeed setDelegate:self];

twitterFeed is a UIWebView set to go to Twitter's mobile site, but that's beside the point. I'm getting the error "Sending 'SocialView (the name of the class that this is in) to parameter of incompatible type 'id'. I don't know how to fix it. Is there any way to do this quickly and without restructuring my code too much?

Also, it is worth noting that SocialView is a UIViewController, if that's at all important to you.


回答1:


You could put <UIWebViewDelegate> in your SocialView interface declaration and see if that fixes the warning:

@interface SocialView : UIViewController <UIWebViewDelegate> {
...
}



回答2:


If you are in a static method (with a +), you can manually get ride of the warning with a cast:

[twitterFeed setDelegate:(id<UIWebViewDelegate>)self];

If you are in an instance method (with a -), you should follow chown solution.




回答3:


You probably want to read up on how delegates are used. How does a delegate work in objective-C? Make sure you know what you do when you use them.



来源:https://stackoverflow.com/questions/7745838/sending-class-to-parameter-of-incompatible-type-iduiwebviewdelegate-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!