我正在尝试使用NSTimer的userinfo传递UIButton.我已经阅读了NSTimers上有关stackoverflow的每篇文章.我变得非常接近,但却无法到达那里.这篇文章有所帮助
func timeToRun(ButonToEnable:UIButton) {
var tempButton = ButonToEnable
timer = NSTimer.scheduledTimerWithTimeInterval(4, target: self, selector: Selector("setRotateToFalse"), userInfo: ["theButton" :tempButton], repeats: false)
}
Run Code Online (Sandbox Code Playgroud)
计时器运行的功能
func setRotateToFalse() {
println( timer.userInfo )// just see whats happening
rotate = false
let userInfo = timer.userInfo as Dictionary<String, AnyObject>
var tempbutton:UIButton = (userInfo["theButton"] as UIButton)
tempbutton.enabled = true
timer.invalidate()
}
Run Code Online (Sandbox Code Playgroud)