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

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

Luke Irvin
  • 1,179
  • 1
  • 20
  • 39

1 Answers1

0
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.

Alastair Stuart
  • 4,165
  • 3
  • 36
  • 33
  • - (void)showImageFromFilter { if ([brandTextField.text isEqualToString:@"Awake"]) { womenTopImageView.image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"awake_top_purple.png"]]; womenTopImageView.contentMode = UIViewContentModeScaleAspectFit; } } – Luke Irvin Sep 13 '11 at 16:33
  • This look better? The image is still not being displayed. Should that code be added in the viewDidLoad or the - (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component – Luke Irvin Sep 13 '11 at 16:33
  • Also, I am getting this if I try adding [self showImageFromFilter]; in the didSelectRow method – Luke Irvin Sep 13 '11 at 16:36