我有一个像这样的瓷砖对象
- (id)initWithFrame:(CGRect)frame withImageNamed:(NSString*) imageName value:(int) tileValue{
if (self = [super initWithFrame:frame]) {
//initilization code
image = [[UIImageView alloc]
initWithImage: [UIImage imageNamed: imageName]];
image.frame = self.bounds;
image.opaque = YES;
[self addSubview:image];
valueOfTile = tileValue;
} return self;
}
我正在尝试创建一个对象:
tile1 = [[TileView alloc]
initWithFrame:CGRectMake(20,20, 100, 150)
value:1
withImageNamed:@"tile1.png"];
当我没有添加值信息时,我能够让它工作,但它现在给我这个错误:实例方法'-initWithFrame:value:withImageNamed:' not found (return type defaults to 'id')
我不确定我在哪里出错了。
答案 0 :(得分:3)
该方法定义为initWithFrame:withImageNamed:value:
,但您将其称为initWithFrame:value:withImageNamed:
。你需要这样称呼它:
tile1 = [[TileView alloc]
initWithFrame:CGRectMake(20,20, 100, 150)
withImageNamed:@"tile1.png"
value:1];
答案 1 :(得分:1)
您的方法签名和调用它的方式不匹配:参数的顺序不同。将您呼叫中的最后两个参数交换为initWithFrame...
,它应该有效。