在 SWTableViewCell 中,UtilityButtons 不响应 setTag 属性

In SWTableViewCell, UtilityButtons not responding to setTag Property

我正在使用 SWTableViewCell 覆盖标准 TableViewCell 以显示其可滑动的左右实用按钮, 我能够访问故事板 segue 或者我能够 segue 到 detailViewController。

但是我的实用按钮有问题setTag 属性

如何访问 UitlityButtons 行的 IndexPath 而我已经尝试了以下内容。

NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
NSLog(@"selected favourite button tag %ld",(long)indexPath);

在模拟器中,它对每一行每次都给出相同的结果。

selected favourite button tag 0

获得按钮“setTag”属性的任何解决方案,以便在按下时像在普通 tableview 中一样访问 SWTableViewCell 中那些实用程序按钮的行的索引路径

如何访问 Utility 按钮的 setTag 属性 以在按下时访问包含该特定按钮的行的 indexPath。

你必须利用SWTableViewCellDelegate。在 UITableViewDataSourcecellForRow 方法中返回单元格时,将单元格的委托设置为您的视图控制器 (cell.delegate = self) 并实现 SWTableViewCellDelegate 协议。

SWTableViewCellDelegate:

- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerLeftUtilityButtonWithIndex:(NSInteger)index;
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index;

在这两种委托方法中的任何一种中,您都可以访问按下实用程序按钮的单元格的 indexPath,如下所示:

NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
NSLog(@"Index path: %@", indexPath);

这里有 indexPath.