获取cell里按钮的section和row

1 给cell里的按钮添加点击事件,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

ServiceTypeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

if (cell == NULL) {

cell = [[ServiceTypeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];

cell.selectionStyle = UITableViewCellSelectionStyleNone;

cell.separatorInset = UIEdgeInsetsZero;

cell.clipsToBounds = YES;

}

[cell.goBtn addTarget:self action:@selector(goBtnAction:event:) forControlEvents:UIControlEventTouchUpInside];

return cell;

}

2 获得按钮的位置。

- (void)goBtnAction:(id)sender event:(id)event

{

//获取触摸点的集合,可以判断多点触摸事件

NSSet *touches=[event allTouches];

//两句话是保存触摸起点位置

UITouch *touch=[touches anyObject];

CGPoint cureentTouchPosition=[touch locationInView:self.myTableView];

//得到cell中的IndexPath

NSIndexPath *indexPath=[self.myTableView indexPathForRowAtPoint:cureentTouchPosition];

NSLog(@"section----%li,----row---%li",(long)indexPath.section,(long)indexPath.row);



}

你可能感兴趣的:(获取cell里按钮的section和row)