- (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 {
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);
}
}