2017-12-18 157 views
0

我有一個問題與斯威夫特3行動選擇器 - 或者,我可以說,與手勢識別器。斯威夫特3通過按鈕/手勢識別器動作到其他功能使用選擇器

假設我在一個表格視圖中,我通過表格單元格獲得動態數據。我在表格視圖中有一個按鈕或手勢識別器,我想將該按鈕或手勢的數據發送到不同的功能。

+1

請嘗試添加一些代碼並顯示您迄今嘗試過的內容。 –

回答

1

請嘗試下面的功能,希望它能爲你工作!

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. 


} 
+0

感謝兄弟,在案例手勢識別器以及按鈕中,它都非常適合我,如上所述。 –

+0

歡迎bro @neeraj jangid –