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.
}
Don’t compare strings like this. This is checking for pointer equality, not string equality. Use
Your image is not getting set because the two pointers are not equal.