我想創建一個通用按鈕創建函數到我傳遞表示結果點擊按鈕的結果作用的封閉使用。我的代碼如下。但是,我收到以下錯誤: #selector的參數無法引用屬性。任何解決方法的建議?我不想編寫單獨的函數,除了目標操作外,其他所有內容都是相同的。斯威夫特作爲參數傳遞關閉由選擇器功能
func myButton(textColor tColor:UIColor , title:String,
_ buttonFcn: (UIButton) -> Void,
titleSize:CGFloat=30) -> UIButton {
let newButton = UIButton(type: .System)
let bgColor = UIColor(red:204/255, green:204/255, blue:204/255, alpha:1.0)
newButton.backgroundColor = bgColor
newButton.setTitle(title, forState: .Normal)
newButton.setTitleColor(tColor, forState: .Normal)
newButton.titleLabel?.font = newButton.titleLabel?.font.fontWithSize(titleSize)
newButton.addTarget(self, action:#selector(buttonFcn),
forControlEvents:
UIControlEvents.TouchUpInside)
return newButton
}
的可能的複製[我可以#selector指的是斯威夫特封閉?](http://stackoverflow.com/questions/36983633/can-i-make-selector-refer-to-a-closure-in -swift) – davecom