2012-07-20 142 views
0

這是我的第一個問題。什麼是UIButton backgroundImage鍵? iOS

我試圖以編程方式更改UIButton的背景圖像,但有一個問題,我無法找到背景圖像的關鍵。 明白了,這是我的代碼:

[[self.view viewWithTag:69000+i] setValue:[UIImage imageNamed:[NSString stringWithFormat:@"%d-options.png", i+1]] forKey:@"backgroundImage"]; 

當這樣執行,應用程序崩潰。給予此錯誤:

主題1:信號SIGTRAP在main.m文件
並在調試:(LLDB)

所以,如果我是正確的,並墜毀是由不正確引起的鍵(backgroundImage),引用背景圖片的關鍵是什麼?

非常感謝!

PD:我需要self.view viewWithTag完成這件事......

回答

1

而且你爲什麼不這樣做:

if([[self.view viewWithTag:69000+i] isKindOfClass:[UIButton class]]) 
    { 
     UIButton *currentButton = (UIButton *)[self.view viewWithTag:69000+i]; 
     [currentButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d-options.png", i+1]] forState:UIControlStateNormal]; 
    } 
+0

+1我想和backgroundImage所以我糾正它,它的工作!我不知道isKindOfClass方法。儘管按照我的方式改變背景圖像的關鍵是什麼?謝謝! – 2012-07-20 15:42:57

+1

您無法通過將其分配給某個鍵來進行設置。這不是一本字典。您只能使用'setImage:forState:'和'setBackgroundImage:forState:'來設置'UIButton'的'image'和'backgroundImage'屬性。 – 2012-07-20 15:56:43

+0

@JustinPaulson瞭解。謝謝! – 2012-07-21 16:07:49

相關問題