2012-07-17 40 views
1

我有一個tableView,我在一個單元格上創建一個按鈕。NSInvalidArgumentException ||無法識別的選擇器發送到實例

UIButton *deleteGroupButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [deleteGroupButton setFrame:CGRectMake(218, 12, 40, 60)]; 
    [deleteGroupButton addTarget:self action:@selector(deleteGroupButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; 

當我點擊按鈕,一個異常發生與該消息:

「終止應用程序由於未捕獲的異常 'NSInvalidArgumentException' 的,原因是:「 - [組deleteGroup:]: 無法識別的選擇發送到實例0x5a8afc0' 「

這就是我的deleteGroupButtonClicked方法

- (void) deleteGroupButtonClicked: (id) sender {  

    Groups *tmpGroups = [[Group alloc] init]; 
    NSInteger tmp = appDelegate.selectedGroupId; 
    [tmpGroups deleteGroup:tmp]; 
    [tmpGroups release]; 
} 

回答

1

您的deleteGroupButtonClicked東西有點奇怪:方法,

你有Groups類的對象,但你alloc'ing Group類的對象。我猜GroupsGroup對象的集合。在這種情況下deleteGroup:方法將只存在於Groups類中。

+0

非常感謝你。我看不到這是一個問題,我改變了它,但問題沒有解決。通過更改參數「appDelegate.selectedGroupId」解決問題發送了我在不同方法中執行的相同視圖。 對不起我英語不好,再次感謝。 – mozkarakoc 2012-07-17 08:08:06

+0

你可以發佈你的Groups類定義,我會看看。 – 2012-07-17 08:27:23

0

只需用以下內容替換您的deleteGroupButtonClicked方法:

- (void) deleteGroupButtonClicked: (id) sender 
{  

Groups *tmpGroups = [[Groups alloc] init]; 
NSInteger tmp = appDelegate.selectedGroupId; 
[tmpGroups deleteGroup:tmp]; 
[tmpGroups release]; 
} 
+0

有什麼區別? – dreamlax 2012-07-17 08:24:07

+0

早些時候您已經使用過: 組* tmpGroups = [[Group alloc] init]; now Groups * tmpGroups = [[Groups alloc] init]; 羣/組是差異 – 2012-07-17 08:30:19

相關問題