Reputation: 109
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
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
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
Reputation: 4473
I think the convention is to call [super viewDidLoad] in the beginning of viewDidLoad.
There are several checkpoints
Upvotes: 0