处理单元格中 UIImageView 的触摸时出错?

发布于 2024-12-25 13:30:20 字数 1200 浏览 3 评论 0原文

我不知道为什么会发生这种情况,但我收到此错误:

-[__NSArrayM 部分]:无法识别的选择器发送到实例 0x7e53b70 2012-01-07 15:35:44.108 Timely1[51661:15203] * 终止 应用程序由于未捕获的异常“NSInvalidArgumentException”,原因: '-[__NSArrayM 部分]:发送到实例的无法识别的选择器 0x7e53b70'

handleTouch 被激活时。这是我添加图像和点击手势的代码。

[cell.imageView setUserInteractionEnabled:YES];
[cell.imageView setImage:[UIImage imageNamed:@"checkbox.PNG"]];

UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTouch:)];
tapped.numberOfTapsRequired = 1;
[cell.imageView addGestureRecognizer:tapped];   
[tapped release];

然后是我处理触摸的代码:

-(void)handleTouch:(UITapGestureRecognizer *)gesture
{
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[array count] inSection:1];
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

    [cell.imageView setImage:[UIImage imageNamed:@"checkbox_checked.PNG"]];
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:array] withRowAnimation:UITableViewRowAnimationFade];
}

更新:如果我想取消选中它(比如切换它),有人知道该怎么做吗?

I don't know why this is happening, but I get this error:

-[__NSArrayM section]: unrecognized selector sent to instance 0x7e53b70 2012-01-07 15:35:44.108 Timely1[51661:15203] * Terminating
app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[__NSArrayM section]: unrecognized selector sent to instance
0x7e53b70'

when handleTouch is activated. Here is my code for adding the image and tap gesture.

[cell.imageView setUserInteractionEnabled:YES];
[cell.imageView setImage:[UIImage imageNamed:@"checkbox.PNG"]];

UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTouch:)];
tapped.numberOfTapsRequired = 1;
[cell.imageView addGestureRecognizer:tapped];   
[tapped release];

and then my code for handling the touch:

-(void)handleTouch:(UITapGestureRecognizer *)gesture
{
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[array count] inSection:1];
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

    [cell.imageView setImage:[UIImage imageNamed:@"checkbox_checked.PNG"]];
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:array] withRowAnimation:UITableViewRowAnimationFade];
}

UPDATE: How about if I wanted to uncheck it (like toggling it) does anybody know how to do that?

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

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

发布评论

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

评论(2

马蹄踏│碎落叶 2025-01-01 13:30:20

在你的handleTouch方法中我认为你可以使用:

UIImageView *cellImageView=(UIImageView *)gesture.view;

In your handleTouch method i think you could use:

UIImageView *cellImageView=(UIImageView *)gesture.view;
单挑你×的.吻 2025-01-01 13:30:20

我决定使用 UIButton 作为我的复选框,并对我的 UITableViewCell 进行子类化,它看起来更容易、更合乎逻辑,尤其是在切换位方面。

I have decided to go with a UIButton as my checkbox and subclassing my UITableViewCell, it seems easier and more logical especially with the toggling bit.

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