Mattias
Mattias

Reputation: 65

Press button and go to random view in Xcode

I have three different views in my iPhone app, and when the user presses a button, I need the view to change to either of the three views randomly. How do you do that? I have searched for answer everywhere.

Thanks in advance!

Upvotes: 3

Views: 952

Answers (2)

Tendulkar
Tendulkar

Reputation: 5540

you can use the arc4random() method to generate the random numbers.If you want to generate numbers upto 100 then use the modular division h 100.like arc4random() % 100;.And then you can use your code to switching between the views.

Upvotes: 2

mayuur
mayuur

Reputation: 4746

- (IBAction) yourBtnPressed : (id) sender
{
   int i = arc4random() % 3;
   if(i == 1)
   {
           //load first view
   }
   else if(i == 2)
   {
           //load second view
   }
   else
   {
           //load third view
   }
}

Upvotes: 4

Related Questions