tableViewCell上的图片点击,cell变灰,点击其它cell跳转的indexPath不对

在tableViewCell上有一张可以点击的图片,通过Target-Action给图片的imageView添加了点击事件.

但是,在点击图片实现放大效果的时候,图片的背景cell变灰,再次点击其它cell进行页面跳转时,协议方法中得indexPath是刚才点击图片的背景cell的indexPath,不是当前点击的

 

开始是在图片点击事件中 增加了让选中的cell失去选中状态,但是背景cell只是变灰了,没有选中的cell,所以这个方法不好用.

后来 在自定义的cell中增加了touchesBegan的重写,代码如下

 1 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
 2     UITouch * touch = [touches anyObject];
 3     //方法1
 4 //    CGPoint point = [touch locationInView:self];
 5 //    if ([[self hitTest:point withEvent:event] isEqual:self.contentView]) {
 6 //        //点击到自己了
 7 //        [super touchesBegan:touches withEvent:event];
 8 ////        NSLog(@"1.dianziji == %@.",self);
 9 ////        NSLog(@"2.nextResponder == %@",self.nextResponder);
10 //    } else {
11 //        //没点击自己
12 ////        NSLog(@"3.dianziji == %@.",self);
13 ////        NSLog(@"4.nextResponder == %@",self.nextResponder);
14 //    }
15     
16     //方法2
17     UIView *view = [touch view];
18     if ([view isEqual:self.contentView]) {
19         [super touchesBegan:touches withEvent:event];
20     }
21 }
22 
23 @end

 

 
posted @ 2015-02-10 17:24  lxl奋小斗  阅读(753)  评论(0编辑  收藏  举报