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;
    //在这里加入自己的逻辑
    ⋯⋯
    }
  • 相关阅读:
    pinfinder
    华为方舟编译器
    SSH安全加固
    KindEditor
    SQL SERVER 常见SQL和函数使用
    SQL 时间处理
    sqlSQL2008如何创建定时作业(代理服务)(转)
    登录之问题总结
    文件操作(增删查改)
    SQL2008安装后激活方式以及提示评估期已过解决方法(转)
  • 原文地址:https://www.cnblogs.com/sozui/p/4360078.html
Copyright © 2011-2022 走看看