I am trying to prevent a button from being pressed in rapid succession. The app is designed for toddler's.
I am using am IBoutlet to which the button is connect and using button.enabled = false to disable the button and in viewDidApper i have the button.enabled = tru to re-enable the button. This actually executes but has no readl effect. I have attached a code snippet. Does anyone have a suggestion as to how this might be accomplished where the button does not become immediately available? Tried using sleep which actual achieved the goal but I believe this likely not the best solution.
@IBOutlet weak var btn1a: UIButton!
@IBAction func buttonPressed1(sender: UIButton) {
switch title {
case "btn1a":
var soundURL: NSURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("01-S", ofType: "mp3")!)!
var error:NSError?
audioPlayer = AVAudioPlayer(contentsOfURL: soundURL, error: &error)
audioPlayer.prepareToPlay()
audioPlayer.play()
/
btn1a.enabled = false
default:
break
} /
} /
override func viewDidLoad() {
super.viewDidLoad()
/
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
/
btn1a.enabled = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
/
}
}
Galen Murrey