objective c子类UIImageView [英] objective c subclass UIImageView

查看:101
本文介绍了objective c子类UIImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试子类化 UIImageView 以在其中添加一些自定义功能。我开始尝试做基础知识,只是使用给定图像初始化一个对象并将其显示在屏幕上。

使用 UIImageView 一切正常,但是如果我将我的对象从 UIImageView 更改为我的自定义类,则不显示任何图像。

这是我到目前为止所做的:

I'm trying to subclass UIImageView to add some custom functionality in it. I started trying to do the basics, just init an object with a given image and display it on the screen.
Using UIImageView everything works fine, but if i change my object from UIImageView to my custom class, no image is displayed.
Here's what i've done so far:

//Imager.h
#import <UIKit/UIKit.h>
@interface Imager : UIImageView {

}

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

@end

//Imager.m
#import "Imager.h"
@implementation Imager
@synthesize image;


-(id)init
{
    self = [super init];
    return self;
}

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

     //Not implemented yet
}
@end

所以,我正在使用这个声明: cell.postImage.image = [UIImage imageNamed:@img.png];

在执行此操作之前,我还有 postImage = [[UIImageView alloc] init];

So, i am using this statment: cell.postImage.image = [UIImage imageNamed:@"img.png"];
Before this is executed, i also have postImage = [[UIImageView alloc] init];

如果postImage被声明为UIImageView,一切都按预期工作。但如果我改为将其更改为Imager,则不会显示任何内容。
我缺少什么?

If postImage is declared as UIImageView everything works as expected. But if i change it to Imager instead, then nothing is displayed. What am i missing?

推荐答案

你正在合成 image ,当你试图使用点符号来阻止对超类(即 UIImageView )的 setImage 的调用设置图像。

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.

删除此行:

@synthesize image;

这篇关于objective c子类UIImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆