我得到一個函數作爲函數參數,並希望在#selector中設置它。 但我得到的錯誤信息:將函數傳遞給#selector
Argument of '#selector' cannot refer to a property
我有以下功能:
private func addGestureRecognizerToItem(selector:() ->()) {
let labelGesture = UITapGestureRecognizer(target: self, action: #selector(selector))
let imageGesture = UITapGestureRecognizer(target: self, action: #selector(selector))
label.addGestureRecognizer(labelGesture)
imageView.addGestureRecognizer(imageGesture)
}
任何想法如何處理這個問題?
不可能的,因爲目標是'self',你不能傳遞閉包'UIGestureRecognizer' –