使用 UITableViewCellaccessoryView 成员的两个 UIButton 制作自定义 UIView 会导致无法识别的选择器发送到实例错误

发布于 2024-10-23 19:17:47 字数 1411 浏览 4 评论 0原文

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

以下是我用来在cellForRowAtIndexPath UIButton* minus = [[UIButton buttonWithType:UIButtonTypeRoundedRect] 保留]; [减去 setFrame:CGRectMake(0, 0, 30, 30)]; [减去 setTitle:@"-" forState:UIControlStateNormal]; [减去 addTarget:self action:@selector(subtractOne:event:) forControlEvents:UIControlEventTouchDown]; UIButton* 加 = [[UIButton buttonWithType:UIButtonTypeRoundedRect] 保留]; [加上 setFrame:CGRectMake(30, 0, 30, 30)]; [加上 setTitle:@"+" forState:UIControlStateNormal]; [加上 addTarget:self 操作:@selector(addOne:event:) forControlEvents:UIControlEventTouchDown]; UIView* customAccessory = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)]; [customAccessory addSubview:减]; [customAccessory addSubview:plus]; cell.accessoryView = customAccessory; [自定义配件发布];

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

- (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'

I'm trying to make a view with two buttons for a table cell accessory view to do two (obviously) different things to the object at that cell index. I made two basic rounded rect UIButtons with a selector in the RootViewController (where the UITableView resides). Here is the code I use to initialize this view in a cell that is found in the cellForRowAtIndexPath method:


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

And the two methods they call are defined:


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

Any ideas why this would throw unrecognized sender sent to instance "RootViewController"?

Here is the full error:

2011-03-20 20:34:35.493 MyApp[23262:207] -[RootViewController subtractOne:event:]: unrecognized selector sent to instance 0x573c350
2011-03-20 20:34:35.496 MyApp[23262:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RootViewController subtractOne:event:]: unrecognized selector sent to instance 0x573c350'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜肉鲜肉永远不皱 2024-10-30 19:17:47

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

Realized my own stupid mistake: Was trying to call on subtractOne:event: when I wrote method for subtractOne:forEvent:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文