开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜