TAGS :Viewed: 7 - Published at: a few seconds ago

[ Need help displaying a UIImage based off selection of UIPicker ]

 - (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;
    }
 }

Here is the general idea of what I am doing.

I have 3 TextFields, each connected to a UIPicker. I have three sets of arrays with values. When I have specific values set I'd like for an image to display below the UITextFields.

This is what I am trying but doesn't seem to be working. Am I on the right track or can someone explain how I can get this to work.

Thanks

Answer 1


brandTextField.text == @"Awake"

This will not compare strings.

[brandTextField.text isEqualToString:@"Awake"]

That will compare strings.

Another issue:

Just use

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

to get your UIImage, initWithContentsOfFile requires a full path.

You also have a typo on

[super ViewDidLoad]

(lowercase the V).

And I'm not sure that's the best way of hooking up the UIPicker to your showImageFromFilter method.

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.