Reputation: 113
I have my two ViewControllers: FormViewController
segued to CompleteRegisteringViewController
My FormViewController
contains textfields where user writes username, password, confirm password and so on... and a ConfirmButton
But it has conditions to complete registering, for example: if the password field text is different to the confirm password field text and so, if it is, the transition between FormViewController
and CompleteRegisteringViewController
is blocked and the user stay on the FormViewController
to modify encountered errors.
I have already my idea to organize code, but the problem is how to "block" the segue ?
Upvotes: 1
Views: 509
Reputation: 25459
You can use shouldPerformSegueWithIdentifier
method:
override func shouldPerformSegueWithIdentifier(identifier: String!, sender: AnyObject!) -> Bool {
if identifier == "YOUR SEGUE NAME" {
// TODO: Do your validation here
// Return true if the validation pass, otherwise return false
}
}
Upvotes: 3
Reputation: 1386
In objective-c You can actually do this by adding following method into your code
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
if([identifier isEqualToString:@"btnSegue"])
{
return YES;
}
else
{
return NO;
}
}
Lets assume your segue is btnSegue.And if you need the segue to be performed based on some condition you can have following code
if(check)
{
[self performSegueWithIdentifier:@"btnSegue" sender:self];
}
Where check is BOOL
which you can set true or false based on your condition.
Upvotes: 0