2012-05-12 35 views
0

我使用代理來獲得一個選項,用戶選用表中的觀點,但我不斷收到一個錯誤象下面這樣:無法識別的選擇發送到實例0x6d79ed0

2012-05-12 23:26:06.704的測試[4629 :fb03] - [AddContentViewController catPickViewController:didSelectGame:]:無法識別的選擇器發送到實例0x6d79ed0

我在表視圖中記錄了該選項,並且無法將其記錄在我的第一個視圖中。

這是我在表視圖

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    if (selectedIndex != NSNotFound) 
    { 
     UITableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:selectedIndex inSection:0]]; 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } 

    selectedIndex = indexPath.row; 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    cell.accessoryType = UITableViewCellAccessoryCheckmark; 

    NSString *theGame = [games objectAtIndex:indexPath.row]; 
    NSLog(@"%@",theGame); 
    [self.delegate catPickViewController:self didSelectGame:theGame]; 

} 

,這是我的選擇方法:

- (void)CatPickViewController:(CatPickViewController *)controller didSelectGame:(NSString *)theGame 
{ 
    NSLog(@"%@",theGame); 
    category = theGame; 
    self.catDetails.text = category; 

    [self.navigationController popViewControllerAnimated:YES]; 
} 

我知道這個問題是[self.delegate catPickViewController: self didSelectGame:theGame];

但我該怎麼處理它?

我忘了提,我有catPickViewController.h像

@class CatPickViewController; 

@protocol CatPickViewControllerDelegate <NSObject> 
- (void)catPickViewController:(CatPickViewController *)controller didSelectGame:(NSString *)game; 
@end 

@interface CatPickViewController : UITableViewController 

@property (nonatomic, weak) id <CatPickViewControllerDelegate> delegate; 
@property (nonatomic, strong) NSString *game; 

@end 

所以catPickViewController提到你們從這裏

+0

方法簽名幾乎從不以大寫字母開頭。 – CodaFi

+0

在調用'catPickViewController'(在'didSelectRowAtIndexPath:'底部附近)之前記錄'self.delegate'的值並查看它說了什麼。 –

回答

2

要調用catPickViewController,但該方法的名稱拼寫CatPickViewController。您應該將其更改爲catPickViewController

+0

我編輯的問題,你可以看到它不是你所想的,catPickViewController確實存在 – oratis

+0

在CatPickViewController或AddContentViewController中定義的方法在哪裏? – CodaFi

+1

在您現在發佈的文本中,您仍然有在' - (void)CatPickViewController:(CatPickViewController *)控制器didSelectGame:(NSString *)theGame'下的方法實現。這不符合頭文件中的聲明。 – jonmorgan

相關問題