zoukankan      html  css  js  c++  java
  • 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;
    //在这里加入自己的逻辑
    ⋯⋯
    }
  • 相关阅读:
    Server 对象
    Response 对象
    bzoj 5252: [2018多省省队联测]林克卡特树
    bzoj 2167: 公交车站
    bzoj 5315: [Jsoi2018]防御网络
    bzoj 5319: [Jsoi2018]军训列队
    bzoj 4161: Shlw loves matrixI
    bzoj 4942: [Noi2017]整数
    bzoj 2648: SJY摆棋子
    kd-tree 小结
  • 原文地址:https://www.cnblogs.com/sozui/p/4360078.html
Copyright © 2011-2022 走看看