UIImageView 错误

发布于 2024-08-05 09:11:03 字数 842 浏览 4 评论 0原文

我遇到编译器错误,但我无法找出问题所在。我对此很陌生,因此很难破译该错误。

在我的 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

随波逐流 2024-08-12 09:11:03

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 *).

抱着落日 2024-08-12 09:11:03

你可以尝试

loadImageInto = imgNamed ;

you can try

loadImageInto = imgNamed ;
无远思近则忧 2024-08-12 09:11:03

您将 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. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文