-2

I try to perform segue & text field validation on the action of a button. but it performs dismiss segue without validation. i am new for ios & swift.

Siddharth Shah
  • 382
  • 4
  • 22

1 Answers1

1

Create a global Bool variable

var pass=true;

In your button action

@IBAction func Button_Action(sender: AnyObject) {

    if txt_out.text==""   //txt_out will be your UITextField outlet
    {
        pass=false;
    }
    else
    {
        pass=true;
    }
}
override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
    return pass;
}

Or you can directly put validation of UITextField in shouldPerformSegueWithIdentifier method:

override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
    if txt_out.text==""
    {
        return false;
    }
    else
    {
        return true;
    }

}
Bhavin Ramani
  • 3,221
  • 5
  • 30
  • 41