I am trying to use swift's shouldPerformSegueWithIdentifier() method, but it accepts 2 arguments. These are (identifier: String!, sender:AnyObject)
My main goal is to execute the code when pressing a login button in my storyboard, and depending of a series of checks return TRUE or FALSE, depending if whether the correct username and password were provided. So here are my questions:
What am I supposed to use as the identifier? Apple's documentation it explains that the identifier is a string that identifies the triggered segue. So suppose that my segue had the name of loginSegueProcess. How could I use it in my ViewController tat is assigned to my UIView? The thing is that I declare the method in my code and it requires me to specify both arguments (identifier & sender). How could I provide the arguments?
Will this method actually fulfill my needs? By that I mean if it will indeed stop the segue transition whenever my Login button is clicked and depending on whether the correct credentials were provided it is going to take you to the next View or it will show, say for example, an AlertView.
Finally, I was thinking that the performSegueWithIdentifier(args) method would help me as well. Does anybody know the difference between them?
Thanks a lot in advance!
isn't it what you want to do?
You may not invoke
shouldPerformSegueWithIdentifier()
method by yourself. It will be automatically called just before transition to the next view giving a chance to determine wether the transition should take place or. You may conditionally return YES/NO from this method. If your condition does't involve any sever call,a simple logical checking this method will be enough for you.performSegueWithIdentifier()
is used to invoke a segue programmatically. Consider the above case with a network call, you may return NO fromshouldPerformSegueWithIdentifier()
initially since authentication is going on. After getting the response from server if it success you can call the segue to execute withperformSegueWithIdentifier
(Here the identifier is the ID you have given in the storyboard). Before make sure you are supposed to return YES fromshouldPerformSegueWithIdentifier()
.Now a third case if your segue is connecting from the login button(You have to connect it from the controller itself). The checking of
shouldPerformSegueWithIdentifier
is no more required. You can just call the segue withperformSegueWithIdentifier()
after getting the success response from server