无法更改 UIImageView 控件中的图像
在我看来,这似乎是一个错误,因为我已经使用以下命令更改了图像:
someImage.image = [UIImage imageNamed:@"anotherImage.png"];
并且我从未遇到过问题。让我向您展示我所拥有的:
我已经放置了一个 UIImageView:
请注意,imgObjetivos 已连接到此UIImageView。
我有一个在单击以下按钮时被调用的方法:
并且该方法包含:
如您所见,我只想更改当前图像:
所以当我在模拟器中运行应用程序,一切看起来都很棒:
,当我按下按钮时,图像成功更改:
< img src="https://i.sstatic.net/AJhw8.png" alt="在此处输入图像描述">
现在为什么当我在 iPad 上运行应用程序时图像没有改变!?当我按下按钮时,图像消失,而不是像模拟器中那样获得新图像。我刚学了 Objective-C,我开始不喜欢它了。我做错了什么?
编辑
我找到了一个解决方案,我更改了图像的名称,现在它可以工作了:
但这没有意义。哪些名称有效,哪些无效?我还确保没有两张同名的图像,但事实并非如此。当“_”下划线后面有几个字母时,它不起作用。这实在是太奇怪了。我开始不喜欢 Objective-C :(
This seems to me as a bug because I have changed images with:
someImage.image = [UIImage imageNamed:@"anotherImage.png"];
and I have never had a problem. so let me show you what I have:
I have placed an UIImageView:
note that imgObjetivos is conected to this UIImageView.
I have a method that get's called when clicking the following button:
and the method contains:
as you can see I just want to change the current image with:
so when I run the application in the simulator everything looks great:
and when I press the button the image changes successfully:
Now why is it that when I run the application on my iPad the image does not change!? when I press the button the image disappears instead of getting a new image like in the simulator. I just learned objective-c and I am starting to dislike it. What am I doing wrong?
EDIT
I found a solution I changed the name of the image and now it works:
but this makes no sense. Which names works and which ones do not? I also have make sure that I don't have two images with the same name and that is not the case. when I have a few letters after the '_' underscore it does not work. This is really strange. I am starting to dislike objective-c :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我必须将图像名称重命名为其他名称,我不明白为什么...我认为问题是因为我之前删除了包含相同名称的图像,但事实并非如此,因为我使用类似的名称导入了图像解决方案的名称,我遇到了同样的问题。例如,图像的原始名称是 objetivosFoto_h.png,当我重命名为 objetivosFoto_ho.png 时,它仍然不起作用,但当我重命名为 objetivosFoto_horizontal.png 时,它起作用了。
I had to rename the image name to something else I don't understand why... I thought that the problem was because I previously deleted that image that contained the same name but that is not the case because I imported the image with a similar name to the solution and I had the same problem. for example the original name of the image was objetivosFoto_h.png and when I renamed to objetivosFoto_ho.png it still did not work but when I renamed to objetivosFoto_horizontal.png it worked.
我以前也遇到过同样的问题。问题是您用来替换先前图像的图像已损坏或者不是原始格式。
就我而言,我在网上下载了 .jpg 格式的图像,并将其重命名为 .png 格式,这实际上使其成为 .png。所以短期来看,ipad不支持仅通过重命名扩展名来转换图像格式的功能。你必须有一个合适的转换器或其他东西。
I've had the same problem before. The problem is that the image that you're using to replace the previous image is corrupted or say is not in it's original format.
In my case, I downloaded images in the web which was .jpg format and renamed it as .png format which actually made it .png. so in short term, ipad does not support the functionality for converting image format by just renaming the extension. you have to have a proper converter or something.
我会从项目中删除图像文件,清理项目并将文件添加回来。
I would go with removing the image file from the project, clean the project and add the file back.