2012-06-11 38 views
0

我將四到五個視圖添加到UIScrollview。UIButton選擇器錯誤

我在運行時動態創建視圖。

所有視圖都包含一個按鈕。

{ 

    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom]; 

    [button addTarget:self action:@selector(category_selected:) forControlEvents:UIControlEventTouchUpInside]; 

} 

意見添加成功,但是當我點擊按鈕「無法識別的選擇發送到實例0x657e850」所示。我究竟做錯了什麼?

回答

4

您需要在控制器中實施category_selected:方法。簽名應該是這樣的:

- (void)category_selected:(UIButton*)sender 
{ 
    // The sender is the button that was pressed. 
} 

當您設置這樣的按鈕:

[button addTarget:self action:@selector(category_selected:) forControlEvents:UIControlEventTouchUpInside]; 

我假設你是從你的控制器調用這個,所以self是控制器,而是必須實現category_selected:的類。

0

您是否在類中定義了方法category_selected:。

[button addTarget:self action:@selector(category_selected :) forControlEvents:UIControlEventTouchUpInside];

category_selected:方法應該在您設置上述操作的類中定義。

0

我有Category_Selected方法。我打電話給category_selected。

那是我的方法,其第一個字母以大寫字母開頭,但我打電話方法與第一個字母小寫。