代码可以在 iPhone 模拟器上运行,但不能在设备上运行
我使用以下代码在 ipad 应用程序中的两个不同的皮肤/主题之间切换。 该代码在模拟器中运行良好,但在设备上运行不佳。任何人都可以就为什么会发生这种情况提出任何建议吗?
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'm using the following code to switch between two different skins/themes in an ipad app.
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我曾经遇到过一个问题,模拟器正确地选择了资源(图像),但没有正确地选择设备(iPhone)。
至少在我的例子中,结果是图像名称的情况。确保图像的名称与代码中写入的完全相同(button.png / Button.png 等)
只是猜测......
I once faced a problem where Simulator was correctly picking the resources (images) but not the device (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.)
Just a guess...
您的图像可能存在一些问题,它在模拟器中显示正常,但在设备中则不然...只需 4 尝试使用另一个图像代替该图像。
谢谢
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 .
thanks
试试这个:
首先,不要在每次想要更改主题时都分配imgSkinSelector。在 viewDidLoad/loadView 函数中仅分配/初始化一次,如下所示:
然后在您要更改主题的函数中,使用以下代码:
}
else {
}
希望这对您有用。
Try this:
Firstly, don't alloc imgSkinSelector every time you want to change your theme. Alloc/init only once in your viewDidLoad/loadView function like below:
Then in your function, where you are changing theme, use this code:
}
else {
}
Hope this works for you.