点击cell里的Btn获取当前的index

2017-08-21  本文已影响0人  L_Divano

[你的btn addTarget:selfaction:@selector(cellBtnClicked:event:) forControlEvents:UIControlEventTouchUpInside];


- (void)cellBtnClicked:(id)sender event:(id)event{

    NSSet*touches =[event allTouches];

    UITouch *touch =[touches anyObject];

    CGPoint currentTouchPosition = [touch locationInView:你的UITableView];

    NSIndexPath*indexPath= [你的UITableView indexPathForRowAtPoint:currentTouchPosition];

    //UICollectionView使用这句 NSIndexPath*indexPath= [你的UICollectionView     indexPathForItemAtPoint:currentTouchPosition];

    if(indexPath!=nil)  {

        // do something

      }

}
上一篇 下一篇

猜你喜欢

热点阅读