0
 - (void)viewDidLoad
 {
      [super ViewDidLoad];

      [brandTextField addTarget:self action:@selector(showImageFromFilter) forControlEvents:UIControlEventAllEvents];
 }


 - (void)showImageFromFilter
 {
      if (brandTextField.text == @"Awake") 
      {
          NSString * imageString = @"awake_top_purple.png";

          UIImage * womenTopImage = [[UIImage alloc] initWithContentsOfFile:imageString];

          womenTopImageView.image = [[UIImageView alloc] initWithImage:womenTopImage];

         womenTopImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
 }

这是我在做什么的总体思路。

我有 3 个 TextField,每个都连接到一个 UIPicker。我有三组带值的数组。当我设置了特定值时,我希望在 UITextFields 下方显示图像。

这是我正在尝试但似乎没有工作。我在正确的轨道上还是有人可以解释我如何让它发挥作用。

谢谢

4

1 回答 1

0
brandTextField.text == @"Awake"

这不会比较字符串。

[brandTextField.text isEqualToString:@"Awake"]

这将比较字符串。

另一个问题:

只需使用

[UIImage imageNamed:@"awake_top_purple.png"];

要获取您的 UIImage,initWithContentsOfFile 需要完整路径。

你也有错字

[super ViewDidLoad]

(小写 V)。

而且我不确定这是将 UIPicker 连接到 showImageFromFilter 方法的最佳方式。

Have a read through of Apple's sample code and documentation, you'll get a much better feel for how things are supposed to work.

于 2011-09-13T16:24:29.930 回答