简体   繁体   English

Xcode 5错误:表达式结果未使用

[英]Xcode 5 Error: Expression result unused

So I am coding in Xcode 5 and I am working on a project that allows people to save an image that is displayed on the image view. 所以我在Xcode 5编码,我正在开发一个项目,允许人们保存图像视图上显示的图像。 I typed in this code... 我输入了这段代码......

[starImageView initWithImage:[UIImage imageNamed:@"star.jpg"]];

And then this error/warning came up... 然后出现了这个错误/警告......

"Expression result unused" “表达结果未使用”

If you have ANY other questions about my project, let me know! 如果您对我的项目有任何其他疑问,请告诉我们!

ALL answers are GREATLY appreciated!!! 所有答案都非常感谢!!!

Thanks! 谢谢!

Eric 埃里克

According to Apple documentation , initWithImage is an instance method , which returns an UIImaveView object instance. 根据Apple文档initWithImage是一个实例方法 ,它返回一个UIImaveView对象实例。

It does two things: 它做了两件事:

1: adjusts the reciever's frame (in your case starImageView) to match the size of the specified image 1:调整接收器的帧(在您的情况下为starImageView)以匹配指定图像的大小

2: Returns another UIImageView initialized with the specified image. 2:返回使用指定图像初始化的另一个UIImageView。

Why you are getting the warning: You are not assigning the object returned by the method call. 为什么要收到警告:您没有分配方法调用返回的对象。 You should have something like this to get rid of this warning: 你应该有这样的东西摆脱这个警告:

id newImageView = [starImageView initWithImage:[UIImage imageNamed:@"star.jpg"]];

(Then you will get a warning unused variable for newImageView, as you are assigning value but not using it anywhere) (然后你会得到一个警告newImageView的未使用变量,因为你正在分配值但不在任何地方使用它)

如果starImageView已经初始化并且您尝试将图像设置为imageview,那么您应该使用以下语句。

[starImageView setImage:[UIImage imageNamed:@"star.jpg"]];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM