Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Can an unwind segue be aborted using code inside its unwind action method?

Tags:

ios

segue

abort

Inside my unwind action method for my unwind segue, I send data to a remote database, and it verifies if the information was successfully stored in the database.

I plan on having my verification function return a 0 or 1, for success or failure, and I'm planning on using that as the condition.

I'm curious if there is a way to abort the unwind segue inside of the unwind action method? (Or should I just do this verification before the unwind segue begins and prevent the unwind segue from even beginning somehow?)

I've already read ios segue "cancel" but I don't know what they mean when they say to override the

-[UIViewController shouldPerformSegueWithIdentifier:sender:]

method. Do I just make my own custom version of this method (see below) and call it inside the unwind action method, and make it return no/yes depending on my condition? I tried overriding the method with:

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
    if (database verification fails) {
        return NO;
    }
    return YES;              
}

and I called it inside my unwind action method, however it didn't cancel the unwind segue.

Am I doing something incorrectly, or is there another way to abort the unwind segue inside the unwind action method?

I am new to iOS, so I'm sorry if this question sounds silly. Thanks for any help!

like image 963
giant91 Avatar asked Nov 02 '22 18:11

giant91


1 Answers

It would probably be best if you just check the result of your data base and then perform the segue. The first segment of code that you posted won't get modified that much, but if you already have your unwind segue made and working, then the only thing you would add to your code to check, would be something like this (lets say your database returns YES and you make it an NSString called returnResult):

if ([returnResult isEqualToString:@"YES"])
{
    [self performSegueWithIdentifier:@"unwindSegueName" sender:self];

}
else
{
    //do whatever here if the value equals anything other than "YES"
}

Your if statement will vary depending on the data that you get back from the database, but you would still just use an plain if conditional.

FYI, Posting more code will get you more complete answers. If you posted what the return data from the database looked like, then I could have showed you how to use it.

like image 64
CaptJak Avatar answered Nov 15 '22 12:11

CaptJak