Cosinus
Cosinus

Reputation: 109

UIImageView doesn't show picture

I have an UIImageView and I would like to paste a picture in it, but which picture, it depends from the navigationItem.title.

So here is the code:

- (void)viewDidLoad
{
    if(self.navigationItem.title == @"Кружка")
    {
        giftImage.image = [UIImage imageNamed:@"cup2.png"];
    }
    [super viewDidLoad];
}

No errors, just doesn't work. What's wrong?

I changed my code to this:

- (void)viewDidLoad
{

    [super viewDidLoad];
    if(self.navigationItem.title == @"Кружка")
    {
        giftImage.image = [UIImage imageNamed:@"cup1"];

    }


    [self.view addSubview:giftImage];
    // Do any additional setup after loading the view from its nib.
}

Upvotes: 0

Views: 643

Answers (3)

N C
N C

Reputation: 539

Debug using breakpoints and check whether the If condition is returning true or false... If it returns False, then try again by replacing self.navigationItem.title with self.title

And if it returns true then :

1. Recheck cup2.png spellings (Note that image extension is mandatory)
2. Image names are case sensitive. so recheck letter case in spellings
3. This image must present in xcode resources.

Upvotes: 1

jrturton
jrturton

Reputation: 119292

if(self.navigationItem.title == @"Кружка")

Don't compare strings like this. This is checking for pointer equality, not string equality. Use

if([self.navigationItem.title isEqualToString: @"Кружка"])

Your image is not getting set because the two pointers are not equal.

Upvotes: 3

barley
barley

Reputation: 4473

I think the convention is to call [super viewDidLoad] in the beginning of viewDidLoad.

There are several checkpoints

  1. Debug if it is coming inside the if block.
  2. Check if the giftImage is added as a subview.

Upvotes: 0

Related Questions