ios - UIButton not reacting to first press in Swift -
i working on simple (ok, should simple) calculator estimates risk based on few inputs (toggle on/off)
everything working properly, except uibuttons need tapped 2 times toggle initially. after that, uibuttons work expected.
here code (contained within viewdidload())
@iboutlet weak var confusionbutton: uibutton! var counter = 0 var confusiontoggle = 0
and here action
@ibaction func pressconfusion(sender: uibutton) { if confusiontoggle == 0 { confusionbutton.backgroundcolor = uicolor.clearcolor() confusionbutton.alpha = 1; confusiontoggle++; counter++; } else { confusionbutton.backgroundcolor = uicolor.graycolor() confusionbutton.alpha = 0.5; confusiontoggle = 0 counter--; } }
any thoughts on one? swift skills limited (my first attempt swift)
think getting confused. use print statements first understand happening, fancy button ui changes.
@ibaction func tapbutton(sender: uibutton) { // user println debug println(confusiontoggle) if confusiontoggle == 0 { sender.backgroundcolor = uicolor.graycolor() sender.alpha = 0.5; confusiontoggle++; counter++; } else { // reset sender.backgroundcolor = uicolor.clearcolor() sender.alpha = 1; confusiontoggle = 0 counter--; } }
Comments
Post a Comment