• tableview的点击事件获取行号 indexpath


     UITableView 有一个很关键的方法 indexPathForRowAtPoint,可以根据触摸发生的位置,返回触摸发生在哪一个 cell 的indexPath。 而且通过 event 对象,我们也可以获得每个触摸在视图中的位置:
    
    // 检查用户点击按钮时的位置,并转发事件到对应的accessorytapped事件
    - (void)btnClicked:(id)senderevent:(id)event
    {
    NSSet *touches =[event allTouches];
    UITouch *touch =[touches anyObject];
    CGPointcurrentTouchPosition = [touch locationInView:self.tableView];
    NSIndexPath *indexPath= [self.tableView indexPathForRowAtPoint:currentTouchPosition];
    if (indexPath!= nil)
    {
    [self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath:indexPath];
    }
    }
    
    这样,UITableView的accessoryButtonTappedForRowWithIndexPath方法会被触发,并且获得一个indexPath 参数。通过这个indexPath 参数,我们可以区分到底是众多按钮中的哪一个附件按钮发生了触摸事件:
    
    -(void)tableView:(UITableView*)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath*)indexPath{
    int* idx= indexPath.row;
    //在这里加入自己的逻辑
    ⋯⋯
    }
  • 相关阅读:
    ping与telnet的区别
    TCP连接的建立与关闭
    网络的7层协议
    oracle数据库中,分天查询数目
    求某个字符在字符串中的第5个位置
    高精度乘
    高精度加法
    二叉排序树(建树,先序,中序,后序遍历)
    求哈夫曼树的带权路径长度和
    HDU_1237_简单计算器
  • 原文地址:https://www.cnblogs.com/sozui/p/4360078.html
Copyright © 2020-2023  润新知