UIImageView 错误
我遇到编译器错误,但我无法找出问题所在。我对此很陌生,因此很难破译该错误。
在我的 .h 中,我...
@interface LongViewController : UIViewController {
IBOutlet UIImageView *loadImageInto;
IBOutlet UIImageView *loadedInto;
}
-(void)fadeIt:(UIImageView*)imgNamed;
在我的 .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];
}
我收到的警告位于最后一行,并且是:
warning passing argument 1 of 'imageNamed' from distinct objective-c type
我认为它是说类型错误,但我似乎无法解决它。这可能是说代码运行良好并且图像按预期加载。
任何帮助将不胜感激!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
UIImage imageNamed:
采用 NSString *,它是要加载的图像的名称。听起来您的 imgNamed 变量类型不正确(不是 NSString *)。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 *).你可以尝试
you can try
您将 UIImageView 作为参数传递给该方法,然后在
[UIImage imageNamed:]
方法中使用该值。imageNamed:
方法采用 NSString 作为参数,而不是 UIImageView。因此,您要么需要将图像名称作为 NSString 传递,要么使用 UIImageView 值作为 UIImageView。如果不查看其余代码以及如何创建此 UIImageView,很难判断最佳方法,但从外观来看,您可以简单地编写loadImageInto = imgNamed
。那里你是一个 UIImageView 到另一个。但我怀疑这是否真的有效。所以我建议要么传递 NSString 值,要么发布更多代码。You are passing a UIImageView to the method as a parameter and then using that value in the
[UIImage imageNamed:]
method. TheimageNamed:
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 writeloadImageInto = 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.