ios - 在 SWTableViewCell 中,UtilityButtons 不响应 setTag 属性

标签 ios objective-c uitableview uibutton nsindexpath

我正在使用 SWTableViewCell 覆盖标准 TableViewCell 以显示其可滑动的左右实用按钮, 我能够访问 Storyboard 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”属性以访问 SWTableViewCell 中那些实用按钮的行的索引路径的任何解决方案,就像在普通 tableview 中一样按下时

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

最佳答案

您必须使用SWTableViewCellDelegate。在 UITableViewDataSourcecellForRow 方法中返回单元格时,将单元格的委托(delegate)设置为您的 View Controller (cell.delegate = self) 并实现 SWTableViewCellDelegate 协议(protocol)。

SWTableViewCellDelegate:

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

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

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

这里有indexPath

关于ios - 在 SWTableViewCell 中,UtilityButtons 不响应 setTag 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42478045/

相关文章:

iphone - iOS NSMutableArray 卡住

ios - 解析未检索到或未在 UITableView 中显示的对象

ios - dequeueReusableCellWithIdentifier 然后不使用单元格?

ios - UICollectionView VS UITableview

android - Google Maps Places 不适用于 Android

ios - 使用 nsattributedstring 和 nslocalizedstring

objective-c - 如何在 AppKit 方法中调试发送到 NSNull 对象的无法识别的选择器

objective-c - 检测鼠标悬停在 Dock 上,任何 Dock 图标单击

ios - Swift Uiview 背景动画不起作用

iphone - UIViewController 包含方向变化