0

我有一个像这样的瓷砖对象

- (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')

我不确定我在哪里出错了。

4

2 回答 2

3

该方法定义为initWithFrame:withImageNamed:value:,但您将其称为initWithFrame:value:withImageNamed:。你需要这样称呼它:

tile1 = [[TileView alloc]
             initWithFrame:CGRectMake(20,20, 100, 150)
             withImageNamed:@"tile1.png"
             value:1];
于 2013-04-12T19:06:40.527 回答
1

您的方法签名和调用它的方式不匹配:参数的顺序不同。将调用中的最后两个参数交换为initWithFrame...,它应该可以工作。

于 2013-04-12T19:06:17.040 回答