【发布时间】:2012-01-07 14:41:50
【问题描述】:
我不知道为什么会这样,但我得到了这个错误:
-[__NSArrayM 部分]:无法识别的选择器发送到实例 0x7e53b70 2012-01-07 15:35:44.108 Timely1[51661:15203] * 终止 应用程序由于未捕获的异常“NSInvalidArgumentException”,原因: '-[__NSArrayM section]: 无法识别的选择器发送到实例 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];
}
更新:如果我想取消选中它(比如切换它),有人知道怎么做吗?
【问题讨论】:
-
在我看来,您之前遇到的问题在于 - NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[array count] inSection:1];相反,您需要使用 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[array count]-1 inSection:1];
-
是的,但你知道如何修复
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:array] withRowAnimation:UITableViewRowAnimationFade];,因为我发现这是问题所在,但如果我想再次重新加载一个单元格,我就不能再使用该行了。 -
你是否在数组中传递 NSIndexPath 的对象?
-
这就是我声明我的数组的方式:
array = [NSMutableArray arrayWithArray:db.dbArray];并且 dbArray 是一个包含我所有保存数据的数组。 -
dbarray 中存在什么?您打印了吗?它们是 nsindexpath 的一种吗?
标签: iphone uitableview touch uitapgesturerecognizer