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;
}
}
这里就写一下最近使用的一个很简单的方法:
- (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;
}
}
相关文章推荐
- TableView的cell上面加button,实现点击button可以获取到cell的行号或者indexPath
- tableViewcell button点击 获取cell的indexpath 并刷新当前cell
- UITableView获取cell的row值(解决自定义cell里的button通过点击无法获得cell的indexpath的问题)
- UITableView获取cell的row值(解决自定义cell里的button通过点击无法获得cell的indexpath的问题
- TableView 或者collectionView 获取点击的cell 和当前行数的方法
- C#怎么通过一个按钮Button,实现点击这个按钮可以打开一个文件或者文件夹?
- UITableView获取cell的row值(解决自定义cell里的button通过点击无法获得cell的indexpath的问题)
- iOS中如何通过点击UITableViewCell中的Button来获取当前Cell的indexPath
- tableview的点击事件获取行号 indexpath
- 通过点击cell上的Button获取tableView的indexPath
- 有一个table表格,选中某一行后,点击“查看(button)”按钮可以实现对该行内容的显示
- 点击屏幕获取对应tableviewcell
- 动态tableView中通过点击tableViewCell内部的一个控件找到indexPath
- iOS开发-UITableViewCell(UICollectionViewItem)需要两个手指点击或者长按才可以选中,解决办法
- ImageView 实现从手机相册中获取照片,并可以进行裁剪或者适屏展示
- 如何通过代理之道UItableView上cell上面的button点击的是哪一行的
- 代码拾遗录--轻松获取Cell里的button的indexPath
- 如何获取不同cell上的button点击事件
- 点击button获取text内容并改变样式的js实现
- 怎么不使用didselected方法获取选中的cell的行号,区号,indexPath