如何从单元格中的按钮操作获取tableview中的indexPath? [英] How to get indexPath in a tableview from a button action in a cell?
本文介绍了如何从单元格中的按钮操作获取tableview中的indexPath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含两个操作的 tableview,第一个我使用委托 didSelectRowAtIndexPath,第二个我想在我的单元格上的按钮上使用一个操作来做其他事情.我的问题是我没有成功获得索引路径?这样做的最佳做法是什么.
I have a tableview with two actions in it, for the first on i use the delegate didSelectRowAtIndexPath, for the second one i would like to use an action on a button on my cell to do something else. My problem is that i don't succeed to get the indexpath ? What is the best practice to do that.
推荐答案
如果您已将按钮添加到单元格中,
If you have added the button to the cell as,
[cell.contentView addSubview:button];
然后,你可以得到索引路径,
then, you can get the index path as,
- (void)onButtonTapped:(UIButton *)button {
UITableViewCell *cell = (UITableViewCell *)button.superview.superview;
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
// Go ahead
}
这篇关于如何从单元格中的按钮操作获取tableview中的indexPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文