Search code examples
iosrandomibaction

IBAction that randomly calls different actions?


I would like my IBAction to randomly pick one of the actions in the brackets.

How do I do this?

Thanks!

- (IBAction) randomAction{

[self choice1];
[self choice2];
[self choice3];

}

Solution

  • Try this

    - (IBAction) randomAction{
        switch (arc4random()%3){
            case 0:
                    [self choice1];
                break;
            case 1:
                [self choice2];
                break;
            case 2:
                [self choice3];
                break;
            default:
                break;
        }
    }