【问题标题】:unable to load a UIImage in a UIImageView无法在 UIImageView 中加载 UIImage
【发布时间】:2012-03-11 06:57:57
【问题描述】:

我正在使用 XCode 4.2 开发 iOS 应用

我有一个 UIImage 变量,我试图通过简单地说 imgView=image 将它加载到 UIImageView 中

但我收到一条错误消息:

expected identifier or '('

有人可以帮忙吗

谢谢

已编辑:

我尝试了以下代码:

imgView.image=image;

我收到此错误:

Property 'image' not found on object  of type 'imgView'

【问题讨论】:

  • 请提供更多代码。也试试 imgView.image = img
  • 这是一个编译错误。 Xcode 会给你一个错误和警告列表,以及相关的文件/行。转到与此错误相关的代码并查看语句中是否存在 Objective C 语法问题和/或您使用 UIImageView API 的方式的错误。
  • xlc0212 : 我编辑了我的问题
  • 以后我推荐你阅读Documentation
  • 剪报:我不明白你在说什么,请改写

标签: objective-c uiimageview uiimage xcode4.2


【解决方案1】:

你应该像这样设置 UIImageView 的图像:

imageView.image = image;

编辑:这里有一个更详细的例子:

UIImage *image = [UIImage imageNamed:"@image.png"]; // Change "image.png" by the name of your image file
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame]; // frame is a CGRect.
imageView.image = image;

【讨论】:

  • 我编辑了我的代码,仍然没有工作,检查我编辑的问题
  • 我发现了问题,我的类名和变量相同!!! ,所以 imageview.image=image 有效!
猜你喜欢
  • 1970-01-01
  • 2019-08-07
  • 2011-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多