Image is showing on simulator but not on a real iP

2019-04-20 12:20发布

问题:

So I got this piece of code, I want to show a picture on my view:

imgLogo = [[UIImageView alloc] init];
[imgLogo setFrame:CGRectMake(60, 200, 200, 200)];
[imgLogo setImage:[UIImage imageNamed:@"MyFrigginAwesomeLogo"]];
[self.view addSubview:imgLogo];

But the problem is that it works correctly when testing it on the simulator(iOS 7) but it doesn't show anything on my iPhone(4S with iOS7) itself.

回答1:

Answer added from Comment:

The iOS devices are case sensitive, but the simulator is not. Make sure you are trying to load the exact filename in order for them to be found.



回答2:

Try using the designated initializer for UIImageView instead of just init:

NSString *logoName = @"MyFriggingAwesomeLogo";
imgLogo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:logoName]];
imgLogo.frame = CGRectOffset(imgLogo.frame, 60, 200);
[self.view addSubview:imgLogo];

It's also possible that you've added the image resource to only the simulator target. In your bundle settings Build Phases, make sure you have the image listed in Copy Bundle Resources.