3

我正在尝试使用两个按钮为表格单元格附件视图制作一个视图,以便对该单元格索引处的对象执行两个(显然)不同的事情。我在 RootViewController(UITableView 所在的位置)中制作了两个带有选择器的基本圆角矩形 UIButton。这是我用来在 cellForRowAtIndexPath 方法中找到的单元格中初始化此视图的代码:

UIButton* minus = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; [minus setFrame:CGRectMake(0, 0, 30, 30)]; [minus setTitle:@"-" forState:UIControlStateNormal]; [minus addTarget:self action:@selector(subtractOne:event:) forControlEvents:UIControlEventTouchDown]; UIButton* plus = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; [plus setFrame:CGRectMake(30, 0, 30, 30)]; [plus setTitle:@"+" forState:UIControlStateNormal]; [plus addTarget:self action:@selector(addOne:event:) forControlEvents:UIControlEventTouchDown]; UIView* customAccessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)]; [customAccessory addSubview:minus]; [customAccessory addSubview:plus]; cell.accessoryView = customAccessory; [customAccessory release];

并且定义了他们调用的两种方法:

- (void)subtractOne:(id)sender forEvent:(UIEvent *)event; - (void)addOne:(id)sender forEvent:(UIEvent *)event;

任何想法为什么这会将无法识别的发件人发送到实例“RootViewController”?

这是完整的错误:

2011-03-20 20:34:35.493 MyApp[23262:207]-[RootViewController minusOne:event:]:无法识别的选择器发送到实例 0x573c350 2011-03-20 20:34:35.496 MyApp[23262:207] *终止应用程序由于未捕获的异常“NSInvalidArgumentException”,原因:“-[RootViewController minusOne:event:]:无法识别的选择器发送到实例 0x573c350”

4

1 回答 1

2

意识到我自己的愚蠢错误:试图调用subtractOne:event:当我为subtractOne:forEvent编写方法时:

于 2011-03-21T05:21:31.127 回答