【发布时间】:2011-07-29 04:30:33
【问题描述】:
我正在尝试继承 UIImageView 以在其中添加一些自定义功能。我开始尝试做基础知识,只需使用给定图像初始化一个对象并将其显示在屏幕上。
使用 UIImageView 一切正常,但如果我将对象从 UIImageView 更改为我的自定义类,则不会显示任何图像。
这是我到目前为止所做的:
//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];
如果 postImage 被声明为 UIImageView 一切都按预期工作。但是,如果我将其更改为 Imager,则不会显示任何内容。 我错过了什么?
【问题讨论】:
-
你为什么有
@synthesize image;?你没有定义属性?您的示例中似乎缺少某些内容。
标签: objective-c xcode inheritance uiimageview subclass