iPhone:将 UIImage 添加到 UIImageView 会添加第二个图像
我有一个 UIImageView,我已经为其设置了图像。这工作正常,但稍后,我想更改该图像。因此,我为图像属性设置了一个新图像,但是当我查看应用程序时,该图像被设置为第一个图像之上的第二个图像:
UIImageView *image;
image = (UIImageView *)[cell viewWithTag:0];
image.image = [UIImage imageNamed:@"History_Row2.png"];
如何替换 UIImageView 中的当前图像而不是添加另一个图像?
I have a UIImageView that I have already set an image to. This works fine, but later, I want to change that image. So, I set a new image for the image property, but when I view the app, that image is set as a second image over the first:
UIImageView *image;
image = (UIImageView *)[cell viewWithTag:0];
image.image = [UIImage imageNamed:@"History_Row2.png"];
How can I replace the current image in my UIImageView rather than seeming to add another?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过保留 UIImageView 并将引用保留为 ivar 并在 dealloc 上释放来做到这一点。
I did it by retaining the UIImageView, and keeping a reference as an ivar, releasing on dealloc.
这是返回 UITableViewCell 而不是 UIImageView,这是因为标签 0 是默认值,需要更改为不同的数字。这样做之后就成功了。
That was returning a UITableViewCell rather than a UIImageView, this is because the tag 0 is the default and it needs to be changed to a different number. After doing this it worked.