简体   繁体   中英

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. 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).

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...

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

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM