到SEL進行選擇我創建了下面的代碼UIButton
:鑄造下的Objective-C
UIButton* queenButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
queenButton.frame = CGRectMake(0,50,30,30);
[queenButton setTitle:@"Q" forState:(UIControlState)UIControlStateNormal];
[queenButton addTarget:self action:(SEL)[self performSelector:@selector(promotePawnAt:to:) withObject:end withObject:@"Q"] forControlEvents:UIControlEventTouchUpInside];
當我這樣做,編譯器給出了Cast of an Objective-C pointer to 'SEL' is disallowed with ARC
說,一個錯誤。當我刪除(SEL)
演員時,我得到Implicit conversion of an Objective-C pointer to 'SEL' is disallowed with ARC
。
當按鈕被按下時,我想要做的是讓程序調用promotePawnAt:to:
,但該函數需要參數,所以@selector(promotePawnAt:to:)
不起作用。
,那麼你所做的假設,而不是邏輯思維......精彩...... – 2013-07-29 20:10:26
(提示:你不能直接你想幹什麼無論是重新設計你的代碼,或者使用一個自定義的按鈕子類和一個屬性來存放任何你想要關聯的信息,或者使用Obejctive-C關聯的對象API等等......) – 2013-07-29 20:11:47
你爲什麼不直接調用這個方法從Button的action方法中? – rdelmar