处理单元格中 UIImageView 的触摸时出错?
我不知道为什么会发生这种情况,但我收到此错误:
-[__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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在你的handleTouch方法中我认为你可以使用:
In your handleTouch method i think you could use:
我决定使用
UIButton
作为我的复选框,并对我的UITableViewCell
进行子类化,它看起来更容易、更合乎逻辑,尤其是在切换位方面。I have decided to go with a
UIButton
as my checkbox and subclassing myUITableViewCell
, it seems easier and more logical especially with the toggling bit.