您的位置:首页 > 其它

TableView的cell上面加button,实现点击button可以获取到cell的行号或者indexPath

2017-06-30 10:53 399 查看
在很多时候,我们会用到在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;

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐