Swift 3 使用选择器将 button/gesture 识别器操作传递给其他函数

Swift 3 pass button/gesture recognizer action to other function using selector

我在使用 Swift 3 个动作选择器时遇到问题 - 或者,我可以说,使用手势识别器时遇到问题。

假设我在 table 视图中,我通过 table 单元格获取动态数据。我在 table 视图中有一个按钮或手势识别器,我想将来自该按钮或手势的数据发送到不同的功能。

请试试下面的功能,希望对你有用!!

func whereYouWant(){

let button = UIButton()
button.accessibilityElements = [data1,data2]//Here you can pass any thing in this array.

button.addTarget(self, action: #selector(testFunction), for: .touchUpInside)
}


//Here you can call this function through selector....

func testFunction(myButton:UIButton){

let firstData = myButton.accessibilityElements?[0] as? //Here you can do type cast According to you

let secondData =   myButton.accessibilityElements?[1] as? //Here you can do type Cast According to you.


}