0

我正在使用委托来获取用户在表格视图中选择的选项,但我经常收到如下错误:

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];

}

这就是我所拥有的 select 方法:

- (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 来自这里

4

1 回答 1

2

您正在调用catPickViewController,但方法名称是拼写的CatPickViewController。您应该将其更改为catPickViewController.

于 2012-05-12T15:34:24.783 回答