joshft91
joshft91

Reputation: 1895

Method with multiple parameters

I have a tile object like so

- (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;
}

I'm attempting to create an object:

tile1 = [[TileView alloc]
             initWithFrame:CGRectMake(20,20, 100, 150)
             value:1
             withImageNamed:@"tile1.png"];

I was able to get this to work when I didn't have the value information added, but it's now giving me this error: Instance method '-initWithFrame:value:withImageNamed:' not found (return type defaults to 'id')

I'm not exactly sure where I'm going wrong here.

Upvotes: 0

Views: 111

Answers (2)

Alex
Alex

Reputation: 26859

The method is defined as initWithFrame:withImageNamed:value:, but you're calling it as initWithFrame:value:withImageNamed:. You would need to call it like this:

tile1 = [[TileView alloc]
             initWithFrame:CGRectMake(20,20, 100, 150)
             withImageNamed:@"tile1.png"
             value:1];

Upvotes: 3

TotoroTotoro
TotoroTotoro

Reputation: 17622

Your method signature and the way you invoke it don't match: the order of parameters is different. Swap the last two parameters in your call to initWithFrame..., and it should work.

Upvotes: 1

Related Questions