我正在使用 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
。在 UITableViewDataSource
的 cellForRow
方法中返回单元格时,将单元格的委托(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/