0
votes

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

2
Try only writing tut_1and not tut_1.jpegRandy
Try to create UIImage *testImage = [UIImage imageNamed:@"tut_1.jpeg"]; to check if the image is in asset ?Martin Le
Do you use auto layout in your project?Ulaş Sancak
Yes, I use auto layout.radioaktiv
So the only explanation here is the file can't be found or it is not an image file that UIImage can handle.Ulaş Sancak

2 Answers

2
votes

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.

0
votes

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 !