在很多时候,我们会用到在TableView的cell上面加button,然后在button触发响应时需要获取所点击的button所在的cell的行标,以此来处理一些事件;
这里就写一下最近使用的一个很简单的方法:
- (void)OrderButtonAction:(UIButton *)button type:(AllOrderType)type{
switch (type) {
case DeleteType:{
AppLog(@"点击删除订单");
}
break;
case CancelType:{
AppLog(@"点击取消订单");
}
break;
case GoPayType:{
AppLog(@"去支付 详情");
// 实现点击button可以获取到cell的行号或者indexPath
NSIndexPath *myIndex=[self.myTableView indexPathForCell:(UITableViewCell*)[button superview]];
//如果按钮是加在cell上的contentView上
NSLog(@"myIndex.section==%ld",myIndex.section);
NSLog(@"myIndex.row==%ld",myIndex.row);
TrucallDetailsController *detailsVC = [[TrucallDetailsController alloc]init];
[self.navigationController pushViewController:detailsVC animated:YES];
}
break;
case LogisticsTracking:{
AppLog(@"物流跟踪");
}
break;
case Evaluate:{
AppLog(@"去评价");
}
break;
default:
break;
}
}