radioaktiv
radioaktiv

Reputation: 2549

UIImageView not showing in iOS

I am loading image with text in my ViewController. The text loads and it's fine but the image doesnt.

Here is how I load them in my ViewController:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.backgroundImageView.image = [UIImage imageNamed:@"tut_1.jpeg"];
    self.titleLabel.text = self.titleText;
      NSLog(@"%@",  self.backgroundImageView);
      NSLog(@"%@",  self.backgroundImageView.image);
      NSLog(@"%@",  self.titleLabel.text);

}

The output of the NSLogs is "some text" for the self.titleLabel.text and NULL for the self.backgroundImageView.image.

Strange because NSLog of self.backgroundImageView is not NIL but:

UIImageView: 0x14deaffb0; frame = (0 0; 240 128); autoresize = RM+BM; userInteractionEnabled = NO; layer =

The image tut_1.jpeg exits and the name is written correctly.

I also have the correct outlet referencing in my header file by dragging from the interface builder:

enter image description here

Upvotes: 0

Views: 96

Answers (2)

radioaktiv
radioaktiv

Reputation: 2549

I found the solution. As @Ulas Sancak said the file I was referencing [UIImage imageNamed:@"tut_1.jpeg"] couldn't be handled by UIImage. So I simply converted the image from jpeg to PNG format and it worked !

Upvotes: 0

matt
matt

Reputation: 535945

Possibility 1:

I also have the correct outlet referencing in my header file by dragging from the interface builder

No, you don't. If you log, you will see that self.backgroundImageView is nil, because the outlet from the nib is not hooked up to it.

Possibility 2:

The image tut_1.jpeg exits and the name is written correctly

No, it doesn't. If you log [UIImage imageNamed:@"tut_1.jpeg"], you will see that it is nil.

Upvotes: 2

Related Questions