1

I have a registration view controller. In it I process the input provided by the user soon as he clicks on the register button. This button in the view is connected to an IBAction where I validate the input provided.

How is t possible to trigger the segue and pass the data within the IBAction (not override prepareforsegue) to the next view controller? If the validation fails it shouldn't attempt to execute segue but rather stay on same view to display validation errors.

Thanks for support. The question has been asked in different ways before surely but I wasn't able to find a good combine of segue in ibaction and passing data too.

ksa_coder
  • 1,393
  • 3
  • 15
  • 38

1 Answers1

1

You can create a segue from one view controller to another and can put a check in your button's IBAction, like this:

if (validationPasses)
{
    self.performSegueWithIdentifier("segueIdentifier", sender: self)
}

And if you don't won't to override your prepareforsegue, you can pass the data using delegates.

However, by overriding prepareforsegue, you can pass data to your next view controller like this:

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
if (segue.identifier == "segueIdentifier") {
    // pass data to next view controller
    let vc : NextViewController = segue!.destinationViewController as NextViewController
        vc.someVariable = someValue
      }
}

Here NextViewController is your next viewcontroller, change its name to your next view controller and in this view controller define variable to whom you want to pass value, in this case it is someVariable

Munahil
  • 2,381
  • 1
  • 14
  • 24