我想要继承UIImage,所以我可以包括一个特殊的标题和其他信息,我需要为每个图像。下面是我的.m:尝试子类UIImage,但图像不显示在图像视图
#import "Sticker.h"
@implementation Sticker
//custom init
-(instancetype)initWithTitle: (NSString *)title neededCount: (int)neededCount specialMesage: (NSString *)specialMesage andFilename: (NSString *)path {
self = [super initWithContentsOfFile:path];
if(self) {
self.title=title;
self.neededCount=neededCount;
self.specialMessage=specialMessage;
}
return self;
}
我有一个单一的UIImageView空视图控制器,我试图创建一个新的标签对象,并在使用的UIImageView形象。代码:
Sticker *sticker = [[Sticker alloc] initWithTitle:@"crazy clown" neededCount:50 specialMessage:@"stackoverflow" andFilename:@"clown"];
self.imageView.image=sticker;
self.imageView.hidden=NO;
由于某种原因图像没有显示,也没有错误信息。 “小丑”是Images.xcassets中的pdf图像。任何人都可以给我一些指导,说明为什么这不起作用吗?
为什么它不好继承UIImage? – Kex 2015-03-03 13:58:10
它并不总是坏,但在这种情况下,如果UIImage只是一个像素集合问自己,为什么UIImage应该知道标题,specialMessage和neededCount?我看不到在UIImage中添加这些信息的正当理由。 – 2015-03-03 14:15:42