iPhone Developer Tips Stats: Past 30 days - Pageviews: 88,766 Visitors: 61,679 Thank you everyone! Let's shoot for 100,000 by May. Pass it on...
|
Here’s one that will trip you up if you aren’t careful…look at this code:
timerButton = [[UIButton alloc] initWithFrame:CGRectMake(104, 410, 50, 50)];
// Notice the filename "timer.png"
[timerButton setBackgroundImage:[UIImage imageNamed:@"timer.png"]
forState:UIControlStateNormal];
[timerButton addTarget:self action:@selector(buttonPressed:)
forControlEvents: UIControlEventTouchUpInside];
[self.view addSubview:timerButton];
Simple enough, create a button, use the image timer.png for the normal state, and all is well…if you run this code in the simulator. Problem is, if the actual filename of the image is Timer.png the png file will not appear when running this code on device.
If you haven’t run into this while developing an iPhone app, you can’t fully appreciate how time consuming it can be to track this down.
Note: I ran into this while working with Xcode 3.2.1 and building for iPhone OS 3.1.2
Comments
6 Responses to “Gotcha: Case Sensitive PNG Filename”
Leave Comment
The code works in the simulator because your Mac hard drive was formatted with case insensitive filesystem.
Any version of Xcode & device, has this issue
Thx for the warning!
As the other comments said, the Mac file system is not case sensitive but the iPhone is. So it is important to use matching capitalization when accessing any resource file.
For me I gave the same file name of the Image as case sensitive…….but I dont know why Image is not displaying in the device.
But its working fine in Simulator.
Any one’s help is appreciated.
Monish, here are a few things to try: do a “clean” of all the project files and rebuild; remove the application from the device before re-installing through Xcode; remove the file and add back to the project; rename the file to something numeric 123.png to see what happens.
hey john I tried the things that u suggested before.Even though the inages are not displayed in the device.Would please suggest any other solution for this.I am wasting lots of time on this.
Anyone’s help will be appreciated.
Thank you,
Monish Kumar.