我想通過與NSTimer的用戶信息UIButton。我已經閱讀了NSTimers上的每一篇關於stackoverflow的文章。我越來越近,但不能完全到達那裏。這篇文章已經幫助迅速NSTimer用戶信息
func timeToRun(ButonToEnable:UIButton) {
var tempButton = ButonToEnable
timer = NSTimer.scheduledTimerWithTimeInterval(4, target: self, selector: Selector("setRotateToFalse"), userInfo: ["theButton" :tempButton], repeats: false)
}
功能定時器運行
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()
}
感謝你好這是非常有益的 – user2164327 2015-03-22 10:22:14
沒問題。當你有一刻時,你能標記一個答案嗎?乾杯 – 2015-03-22 17:03:18
此外,您不必絕對必須將字典作爲'userInfo'傳遞,您只需要一個符合「AnyObject?」的對象。就我個人而言,我用它來傳遞'String' – tfrank377 2016-02-24 17:56:04