Is there any way to prevent multiple button click events. In my application i have a scenario where multiple button events are getting called when the user taps the button continuously. Even after adding a loading indicator still sometimes its happening. Is there any generic solution to handle this ?
After trying out different ways like enabling/disabling the button and enabling/disabling the UI (which is not at all recommended) the best way I feel is to use a "bool" variable to check the button clicked status.
`
var isButtonTapped = false
@IBAction func tapButton(sender: Any) {
print("Tap")
if(!isButtonTapped){
//Perform your operations or page navigations. After the navigation operation set the bool value to true.
isButtonTapped = true;
}
}`
Make sure you reset the bool value to false when navigating away from the ViewController
. You can do that in ViewDidDisappear
.