2012-01-07 51 views
1

我不知道为什么发生这种情况,但我得到这个错误:在单元格中处理UIImageView触摸时出错?

-[__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'

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

UPDATE:怎么样,如果我想取消它(如翻转它)没有任何人知道该怎么做?

+0

在我看来,你以前遇到的问题在于 - NSIndexPath * indexPath = [NSIndexPath indexPathForRow:[array count] inSection:1];相反,你需要使用NSIndexPath * indexPath = [NSIndexPath indexPathForRow:[array count] -1 inSection:1]; – rishi 2012-01-07 16:59:43

+0

是的,但是你知道如何修复'[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:array] withRowAnimation:UITableViewRowAnimationFade];'因为我知道那是问题所在,但是如果我想再次加载一个单元格,不再使用该行。 – Souljacker 2012-01-07 17:15:41

+0

你是否在数组中传递NSIndexPath的对象? – rishi 2012-01-07 17:17:35

回答

2

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

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

谢谢你的工作。问题是'[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:array] withRowAnimation:UITableViewRowAnimationFade];',那是什么给了错误。 – Souljacker 2012-01-07 15:43:02

+0

如果我想取消选中它(如切换),你知道该怎么做吗? – Souljacker 2012-01-07 15:50:06

+0

这让我开始了,但我需要更多的数据,然后只是我的图像的状态,所以我决定创建一个类别扩展'@interface UITapGestureRecognizer(Utility)',添加一个额外的属性'@property(nonatomic,strong)id userData;调用userData放置并稍后检索我需要的参数。 – pulkitsinghal 2012-09-04 21:40:09

0

我已经决定了UIButton去为我的复选框,并继承我的UITableViewCell,似乎更容易和更合理的特别是与肘位。