0

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.

1
  • 1
    BTW - The title of this question should be "method with multiple parameters". Commented Apr 13, 2013 at 1:47

2 Answers 2

3

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];
Sign up to request clarification or add additional context in comments.

1 Comment

Bah, I feel dumb now. Thanks.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.