I wrote some codes in viewWillAppear in order to change the background image of some buttons. It works fine in simulator. However, when I load it to a real device, it doesn't work. The device is IOS5.1.1.
Any body knows what's the problem?? Thanks!!
(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
...
//set dataTypeSelect buttons background
UIImage *tmpImage = [UIImage imageNamed:@"White.png"];
[self.dataTypeSelectBut0 setBackgroundImage:tmpImage forState:UIControlStateNormal];
[self.dataTypeSelectBut1 setBackgroundImage:tmpImage forState:UIControlStateNormal];
[self.dataTypeSelectBut2 setBackgroundImage:tmpImage forState:UIControlStateNormal];
tmpImage = [UIImage imageNamed:@"Cyan.png"];
iTDLAppDelegate *tmpAppDelegate = (iTDLAppDelegate *)[[UIApplication sharedApplication] delegate];
switch(tmpAppDelegate.viewingDataType)
{
case EnumDataType_HkHorse:
[self.dataTypeSelectBut0 setBackgroundImage:tmpImage forState:UIControlStateNormal];
break;
case EnumDataType_S1:
[self.dataTypeSelectBut1 setBackgroundImage:tmpImage forState:UIControlStateNormal];
break;
case EnumDataType_S2:
[self.dataTypeSelectBut2 setBackgroundImage:tmpImage forState:UIControlStateNormal];
break;
}
...
}
I have pinpointed it was caused by the image filenames.
The file names are "White.PNG" and "Cyan.PNG".
My codes are as follows
UIImage *tmpImage = [UIImage imageNamed:@"White.png"];
UIImage *tmpImage = [UIImage imageNamed:@"Cyan.png"];
They work fine in simulator but real device.
I found the returned value of tmpImage
is null in real device.
Now I changed them to
UIImage *tmpImage = [UIImage imageNamed:@"White.PNG"];
UIImage *tmpImage = [UIImage imageNamed:@"Cyan.PNG"];
They work fine for both now. :)