swift - 从 cellForItemsInSection 中的 #selector 调用带有两个参数的函数

标签 swift function uicollectionviewcell

这是我的功能:

func myFunction(sender:UILongPressGestureRecognizer, index: Int){
print(sender.view?.tag)
}

在 cellForItemsInSection 中,这是我所做的:

let gesture  UILongPressGestureRecognizer()
gesture.addTarget(self, action: #selector(self.myFunction(_:))) //here I want to call the second parameter with the indexPath.row but how? 
gesture.view?.tag = indexPath.row

最佳答案

您不能在 UIGestureRecognizer 操作中传递两个参数。

来自documentation :

The action methods invoked must conform to one of the following signatures:

- (void)handleGesture;
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer;

关于swift - 从 cellForItemsInSection 中的 #selector 调用带有两个参数的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39636046/

相关文章:

ios - 如何让 slider 以 0.25 为步长移动?

swift - 评估唯一性时忽略软删除条目的数据库约束

ios - 项目在 Xcode 9.0.1 上运行正常,但在 Xcode 9.2 上显示错误

function - VBScript 函数的返回值

ios - UICollectionViewCell 在 collectionview 的多个单元格中看到的一个更改

ios - XCUITest - 如何模拟设备的锁定

javascript - 在 Angular 指令中将函数作为参数传递不起作用

cocoa-touch - UICollectionViewCell 的子类不显示

swift - 如何制作可滑动的 Collection View 单元格以显示删除按钮 Swift

c - 在 C 中按值将结构数组传递给函数