2013-03-05 73 views
0

目前我有一個RootViewControllerPopViewController(popover segue)。iOS:如何從傳遞的圖像字符串填充按鈕圖像

RootViewController我有一個imageView(*卡),它確實與從NSString *valuePopViewController通過圖像文件來填充。

我也有一個Button(* cardButton),我真的很喜歡這個字符串生成的圖像文件被填充。

RootViewController.m

- (void)dismissPop:(NSString *)value { 
NSString *imagefile; 
imagefile = [NSString stringWithFormat:@"%@.png",value]; 
//card.image = [UIImage imageNamed:imagefile]; 
cardButton.currentBackgroundImage = [UIImage imageNamed:imagefile]; 

[[currentPopoverSegue popoverController] dismissPopoverAnimated: YES]; // dismiss the popover 
} 

@end 

我有零之前編程教育,並已完全得到這一步解釋類似的代碼。我打得周圍的UIButton直插

cardButton.currentBackgroundImage = [UIImage imageNamed:imagefile]; 

語法努力使UIButton等同的UIImageView直插

card.image = [UIImage imageNamed:imagefile]; 

其中工程。

當前代碼我得到!賦值給只讀屬性(ERROR)。 請幫助

+0

不,不是的Xcode。 – 2013-03-05 14:21:02

+0

我是新來這個論壇,只是好奇,爲什麼我不應該把它標記爲Xcode,因爲我正在通過Xcode項目工作? – Chameleon 2013-03-05 14:25:09

+0

完美的問題。問題是使用哪個IDE開發項目並不重要。關鍵是它的目標是iOS,並且你正在使用Objective-C語言的Cocoa Touch API。看,自從兩年多以來,我一直在開發應用程序,而且我幾乎沒有使用Xcode :) Make和Clang很好地完成了這項工作。 – 2013-03-05 14:27:03

回答

0

如果你想改變圖像使用此代碼

[cardButton setImage:[UIImage imageNamed:imagefile] forState:UIControlStateNormal]; 

如果你真的想改變背景圖片,然後使用這個

[cardButton setBackgroundImage:[UIImage imageNamed:imagefile] forState:UIControlStateNormal]; 
+0

謝謝你Inder這個工作。 – Chameleon 2013-03-05 14:28:58

+0

@Chameleon如果有效,請花時間接受。 – 2013-03-05 14:41:16