[英]Code works on iPhone simulator but not on the device
I'm using the following code to switch between two different skins/themes in an ipad app. 我正在使用以下代码在ipad应用程序中的两个不同外观/主题之间进行切换。 The code works fine in the simulator but not on the device.
该代码可以在模拟器中正常运行,但不能在设备上运行。 Can anyone give any suggestions as to why this might be happening?
任何人都可以就为什么会发生这种情况提出任何建议吗?
if (skin == 1) {
UIImage* skinSelector = [UIImage imageNamed:@"button1.png"];
self.imgSkinSelector = [[UIImageView alloc] initWithImage:skinSelector];
self.imgSkinSelector.center = CGPointMake(88, 88);
self.imgSkinSelector.alpha = 0;
[self.landscape addSubview:self.imgSkinSelector];
}
else {
UIImage* skinSelector2 = [UIImage imageNamed:@"button2.png"];
self.imgSkinSelector = [[UIImageView alloc] initWithImage:skinSelector2];
self.imgSkinSelector.center = CGPointMake(74, 74);
[self.landscape addSubview:self.imgSkinSelector];
// self.skinSelector.hidden = 1;
}
I once faced a problem where Simulator was correctly picking the resources (images) but not the device (iPhone). 我曾经遇到一个问题,其中模拟器正确地选择了资源(图像)而不是设备(iPhone)。
At least in my case it turned out to be the case of image names. 至少在我看来,这是图像名称的情况。 Make sure the name of image is exactly as written in code (button.png / Button.png etc.)
确保图像名称与代码中的名称完全相同(button.png / Button.png等)
Just a guess... 只是个猜测...
may b some problem with your images it shows fine in simulator but not in device ...just 4 a try use another image in place of that . 可能会使您的图像出现问题,它在模拟器中显示正常,但在设备中却没有...只是尝试4次尝试使用其他图像代替它。 thanks
谢谢
Try this: 尝试这个:
Firstly, don't alloc imgSkinSelector every time you want to change your theme. 首先,不要在每次要更改主题时分配imgSkinSelector 。 Alloc/init only once in your viewDidLoad/loadView function like below:
仅在您的viewDidLoad / loadView函数中分配/初始化一次,如下所示:
self.imgSkinSelector = [[UIImageView alloc] init];
Then in your function, where you are changing theme, use this code: 然后在您要更改主题的函数中,使用以下代码:
if (skin == 1) {
[self.imgSkinSelector setImage:[UIImage imageNamed:@"button1.png"]];
self.imgSkinSelector.center = CGPointMake(88, 88);
self.imgSkinSelector.alpha = 0;
[self.landscape addSubview:self.imgSkinSelector];
} else { }其他{
[self.imgSkinSelector setImage:[UIImage imageNamed:@"button2.png"]];
self.imgSkinSelector.center = CGPointMake(74, 74);
[self.landscape addSubview:self.imgSkinSelector];
} }
Hope this works for you. 希望这对您有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.