Reputation:
I have a compiler error and I just can't work out what is wrong. I am new to this so stuggling to decipher the error.
In my .h I have...
@interface LongViewController : UIViewController {
IBOutlet UIImageView *loadImageInto;
IBOutlet UIImageView *loadedInto;
}
-(void)fadeIt:(UIImageView*)imgNamed;
And in my .m...
-(void)fadeIt:(UIImageView*)imgNamed
{
if(longSize1.alpha == 0.0){
loadImageInto = longSize1;
loadedInto = longSize2;
}
if(longSize2.alpha == 0.0){
loadImageInto = longSize2;
loadedInto = longSize1;
}
loadImageInto.image = [UIImage imageNamed:imgNamed];
}
The warning I am getting is on the last line and is:
warning passing argument 1 of 'imageNamed' from distinct objective-c type
I think it is saying that the type is wrong but I can't seem to sort it out. It is probably saying that the code is running fine and the images are loaded as expected.
Any help would be much appreciated!
Upvotes: 0
Views: 159
Reputation: 342
You are passing a UIImageView to the method as a parameter and then using that value in the [UIImage imageNamed:]
method. The imageNamed:
method takes an NSString as a parameter not a UIImageView. So either you need to instead pass the name of the image as an NSString or use the UIImageView value as a UIImageView. Without seeing the rest of the code and how this UIImageView was created it is hard to judge the best way, but from the looks of it, you could simply write loadImageInto = imgNamed
. There you are one UIImageView to another. However I doubt that is really going to work. So I would suggest either passing the NSString value or posting more code.
Upvotes: 0
Reputation: 12613
UIImage imageNamed:
takes a NSString * which is the name of the image to load. It sounds like your imgNamed variable is not the correct type (not a NSString *).
Upvotes: 1