iOSカスタムUItableViewCellでのbuttonイベント処理


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *my = @"my";
    ButtonCell *cell = [tableView dequeueReusableCellWithIdentifier:my];
    if (cell ==nil) {
        cell = [[ButtonCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:my];
    }
    [cell.button addTarget:self action:@selector(btnClick:event:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}

#pragma mark button  
- (void)btnClick:(id)sender event:(id)event {
    // UIButton *btn = (UIButton *)sender;
    NSSet *touches = [event allTouches];
    UITouch *touch = [touches anyObject];
    CGPoint currentTouchPosition = [touch locationInView:self.tableviews];
    NSIndexPath *indexPath = [self.tableviews indexPathForRowAtPoint: currentTouchPosition];

    if (indexPath) {

        NSLog(@"indexPath.row = %ld", (long)indexPath.row); //  0 tableView cell button  0,  
    }
}