简体   繁体   English

代码可在iPhone模拟器上运行,但不能在设备上运行

[英]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.

相关问题 适用于iPhone Simulator,但不适用于设备 - Works on iPhone Simulator but not on device 代码在iPhone Simulator上崩溃,但可以在实际的iPhone设备上运行? - Code crash on iPhone Simulator but works on actual iPhone device? iPhone 4:Touches在模拟器上有效,但在设备上无效 - iPhone 4: Touches works on simulator but not on device 应用程序只能在iPhone设备上运行,而不能在模拟器上运行 - App works on iPhone device, but not on Simulator 为什么在那里保存和加载文件代码可在iPhone模拟器上运行但在设备上失败 - Why there save and load file code works on iphone simulator but failed on device 在iPhone模拟器中工作正常,但在iPhone设备中锁定 - Works fine in iphone simulator but lockup in an iphone device iPhone HTTP服务器可在模拟器上运行,但不适用于iPhone设备 - iPhone HTTP server works on simulator but not on iPhone device Facebook登录可在iPhone模拟器上使用,但不能在iPhone设备上使用 - facebook login works on iphone simulator but not on iphone device 为iPhone设备而不是为模拟器编译的代码 - Code that compiles for the iPhone Device but not for the Simulator 应用在模拟器上崩溃。 适用于iPhone设备 - App crashes on simulator. Works on iphone device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM