向单个IBAction添加2个不同的动作 - 随机选择

时间:2013-05-29 14:08:47

标签: iphone ios objective-c xcode ipad

目前我已IBAction链接到showLeaderboard,用户按下,没问题。

-(IBAction)RandomView {

[[GameManager sharedGameManager] showLeaderboard:self];

}

然而,如何(如果可能的话)我可以做到这样随机它可能会转到不同的屏幕,也许每隔一个按或类似的东西,所以例如;

 -(IBAction)RandomView {

    [[GameManager sharedGameManager] showLeaderboard:self];

OR

showmy2ndView;

    }

这可能还是太复杂而无法整合?

2 个答案:

答案 0 :(得分:6)

这是在两种可能性之间随机选择的最简单方法:

if (arc4random() % 2 == 0) {
    // do one thing
} else {
    // do another thing
}

答案 1 :(得分:0)

我会使用随机生成器,例如:

int randomVar = arc4Random()%1

然后在randomVar上执行switch语句,在不同的情况下,我会使用'self performSegueWithIdentifier:'方法。