I’m very new to Objective-C. I’m trying to write a method where I create a UIImageView that contains an image file at a specific size.
Here’s my method:
- (void)setImageViewElements:(UIImageView *)imageViewName : (NSString *)imageName : (NSInteger )topX : (NSInteger )topY : (NSInteger )imageWidth : (NSInteger )imageHeight
{
imageViewName = [[UIImageView alloc] initWithFrame:CGRectMake(topX, topY, imageWidth, imageHeight)];
[imageViewName setImage:[UIImage imageNamed:imageName]];
[self.view addSubview:imageView];
}
Xcode throws this warning for the method:
Conflicting parameter types in implementation of ‘setImageViewElements::::::’: ‘CGFloat *’ (aka ‘float *’) vs ‘NSInteger’ (aka ‘int’)
I’d like to call it like this:
[self setImageViewElements:myImageView :@"myImage.png" :150 :532 :112 :82];
Xcode throws this warning for the call:
Incompatible integer to pointer conversion sending ‘int’ to parameter of type ‘CGFloat *’ (aka ‘float *’);
I’ve tried changing the parameters to float, CGFloat and int, but I get the same variation of error.
Any help would be appreciated.
Thanks
Maury
“Conflicting parameter types in implementation…” suggests the method signature in your .h file doesn’t match what you have in the .m file. Maybe your .h still has an older version that uses
CGFloat?As a side suggestion, why not pass in “larger” objects and structs rather than separate image names, x, y, width, and height arguments? Something like:
You would then call it like this:
Using named parameters is generally thought of as good style too.