2017-03-28 7 views
0
@IBAction func attack(_ sender: UIButton) { 


    Timer.scheduledTimer(timeInterval: 3.0, target: self, selector: #selector(self.disableAttackBtn(btnTag:sender.tag)), userInfo: nil, repeats: false) 

} 

func disableAttackBtn(btnTag: Int) { 
    if btnTag == attack1Btn.tag { 
     attack2Btn.isEnabled = false 
    } else { 
     attack1Btn.isEnabled = false 
    } 

    } 

sender.tagデータを、Timer.scheduledTimer内のdisableAttackBtn(btnTag :)関数に渡そうとしています。しかし、 "#selectorの引数は@objcのメソッド、プロパティ、または初期化子を参照していません"というエラーが表示されるこのデータを関数に渡す方法はありますか?どんな助けもありがとう。ありがとうSwift3 Timer.scheduledTimer issue

答えて

0

タイマーアクションでカスタムパラメータを渡すことはできません。

Timer.scheduledTimer(timeInterval: 3.0, target: self, selector: #selector(disableAttackBtn(_:)), userInfo: ["tag" : sender.tag], repeats: false) 
:カスタムパラメータを渡す必要がある場合はTimerインスタンス

disableAttackBtn(_ timer: Timer) 

でなければならないというパラメータ

disableAttackBtn() 

またはパラメータはuserInfo辞書を使用しないeiterサポート

です


fun disableAttackBtn(_ timer: Timer) { 
    let info = timer.userInfo as! [String:Int] 
    let tag = info["tag"]! 
    ... 
+0

私は、int値を渡すためにuserInfo:sender.tagを実行しました。出来た!!ありがとうありがとう!! –