Peeter Vedic Peeter Vedic - 1 year ago 136
Swift Question

Swift press button function, press again for reverse

I've got a simple IBAction that performs a method (let's just say shows subview). When I press this button again I want to perform another method (hides subview).

I have done the coding for the show/hide. I have tried using a Boolean but am unsure of the syntax. I also tried using an if/else statement like this:

var doubleTap = false

if (doubleTap) {
//hide view
} else {
//show view

If someone could shed some light on this that'd be great!

Answer Source

change to code like below in the Button Press Method:

var doubleTap : Bool! = false
if (doubleTap) { 
    //Second Tap 
    doubleTap = false
} else {
    //First Tap 
    doubleTap = true
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download