Próbuję przekazać UIButton za pomocą informacji o użytkowniku NSTimer. Czytałem każdy post na stackoverflow na NSTimers. Zbliżam się bardzo, ale nie mogę się tam dostać. Ten post pomógłSwift NSTimer userinfo
func timeToRun(ButonToEnable:UIButton) {
var tempButton = ButonToEnable
timer = NSTimer.scheduledTimerWithTimeInterval(4, target: self, selector: Selector("setRotateToFalse"), userInfo: ["theButton" :tempButton], repeats: false)
}
funkcja timer biegnie
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()
}
Hi dzięki, który jest bardzo pomocny – user2164327
Nie ma problemu. Czy możesz oznaczyć odpowiedź, gdy masz chwilę. Pozdrawiam –
Dodatkowo, nie musisz koniecznie przekazywać słownika jako 'userInfo', potrzebujesz tylko obiektu zgodnego z' AnyObject? '. Osobiście użyłem go do przekazania 'String' – tfrank377