Ali
Ali

Reputation: 645

Test Before segue push

I'm trying to do some tests in my multiview application before performing a segue push.

when the user push a button, it performs a test, if it's ok : the next view is loaded, if not i do not want to load the next view (stay on the first view or load an other)

Is there a way to do that ?

Xcode 4.3.1

Upvotes: 3

Views: 373

Answers (2)

rdelmar
rdelmar

Reputation: 104082

If the test is ok, you can trigger the segue with performSegueWithIdentifier:sender:, and if it's not ok just do nothing or push another view controller.

Upvotes: 1

CodaFi
CodaFi

Reputation: 43330

Make your method return a Boolean value based on its success, that way you can just test it in an if-else block.

E.G.

-(BOOL)myMethodThatDoesStuff:(NSStuff*)stuff {

    //run the tests and return true
    [self.myView doTrueStuff];
    if (trueStuff) {
        return YES;
    }
    return NO;

}

-(void)conditionalPush
    if ([self myMethodThatDoesStuff:stuff])
         //true
    else {
        //false
    }

Upvotes: 0

Related Questions