The following is the code for an IBAction I would like to disable for 5 seconds after it is clicked.
@IBAction func postPressed(sender: AnyObject) {
//var disableMyButton = sender as? UIButton
//disableMyButton!.enabled = false
//NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector:"enableButton", userInfo: nil, repeats: false)
if(currLocation != nil){
let testObject = PFObject(className: "Hey")
testObject["text"] = self.postView.text
testObject["count"] = 0
testObject["replies"] = 0
testObject["location"] = PFGeoPoint(latitude: currLocation!.latitude , longitude: currLocation!.longitude)
testObject["comments"] = []
testObject["user"] = PFUser.currentUser()
testObject.saveInBackgroundWithBlock({ (success, error) -> Void in
if success {
self.dismissViewControllerAnimated(true , completion: nil)
if let completion = self.completion {
completion(self)
}
}
})
} else {
alert()
}
}
The commented out code is my attempt at disabling the button for 5 seconds, but this code crashes, and I believe it crashed because there is no reference to the enable button.
Typically I would do something like
func enableButton() {
self.button.enabled = true
}
But this won't work since it's an IBAction and theres no reference to the button besides there. Maybe there is a way to do so, but I'm at a loss.
Thanks in advance for some help.