zoukankan      html  css  js  c++  java
  • 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
     
  • 相关阅读:
    winform最大化后不遮挡任务栏
    TabControl控件重绘
    EXT gridPanel 添加图片
    好记性不如烂笔头——double
    好记性不如烂笔头——datagridview相关
    datagridview合并相同单元格
    datagridview问题
    Linux折腾记
    TSC打印机使用教程终极版
    在线直播流测试地址
  • 原文地址:https://www.cnblogs.com/lxllanou/p/4284414.html
Copyright © 2011-2022 走看看