簡體   English   中英

代碼可在iPhone模擬器上運行,但不能在設備上運行

[英]Code works on iPhone simulator but not on the device

我正在使用以下代碼在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;


    }

我曾經遇到一個問題,其中模擬器正確地選擇了資源(圖像)而不是設備(iPhone)。

至少在我看來,這是圖像名稱的情況。 確保圖像名稱與代碼中的名稱完全相同(button.png / Button.png等)

只是個猜測...

可能會使您的圖像出現問題,它在模擬器中顯示正常,但在設備中卻沒有...只是嘗試4次嘗試使用其他圖像代替它。 謝謝

嘗試這個:

首先,不要在每次要更改主題時分配imgSkinSelector 僅在您的viewDidLoad / loadView函數中分配/初始化一次,如下所示:

self.imgSkinSelector = [[UIImageView alloc] init];

然后在您要更改主題的函數中,使用以下代碼:

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];

}其他{

[self.imgSkinSelector setImage:[UIImage imageNamed:@"button2.png"]];
self.imgSkinSelector.center = CGPointMake(74, 74);
[self.landscape addSubview:self.imgSkinSelector];

}

希望這對您有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM