gpt4 book ai didi

xcode - 如何从单元格中的按钮操作获取 tableview 中的 indexPath?

转载 作者:行者123 更新时间:2023-12-04 13:54:05 24 4
gpt4 key购买 nike

我有一个包含两个 Action 的表格 View ,第一个是我使用委托(delegate) didSelectRowAtIndexPath,第二个是我想在我的单元格上的按钮上使用一个 Action 来做其他事情。我的问题是我没有成功获得 indexpath ?这样做的最佳做法是什么。

最佳答案

如果您已将按钮添加到单元格中,

[cell.contentView addSubview:button];

然后,您可以获得索引路径,
- (void)onButtonTapped:(UIButton *)button {

UITableViewCell *cell = (UITableViewCell *)button.superview.superview;
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
// Go ahead
}

关于xcode - 如何从单元格中的按钮操作获取 tableview 中的 indexPath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7452389/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com