objective c subclass UIImageView

谁说我不能喝 提交于 2019-12-06 21:40:35

You're synthesizing image, thus blocking calls to setImage on the superclass (i.e. UIImageView) when you attempt to use the dot notation to set the image.

Remove this line:

@synthesize image;

I would suggest using an Objective-C "Category" instead of subclassing the UIImageView. As long as you don't have to add any member variables, a Category is a better solution. When you use a category you can call your extended functions on any instance of the original class (in your case UIImageView. That removes the need for you to consciously use your subclass anywhere you might want to use your new functions.

You can just do the following in a header:

@interface UIImageView (UIImageView+URL)

-(void) retrieveImageFromUrl: (NSString *)the_URL;

@end

Then in an implimentation file:

@implimentation UIImageView (UIImageView+URL)    

-(void) retrieveImageFromUrl: (NSString *)the_URL
{
    // implimentation
}

@end

Then wherever you want to use your new function on a UIImageView, you just need to include the header file.

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