-1

Using storyboard if user click on button it will navigate to different classes based on random number,i am unable to prepare 3 segues so please help me.

Here my code is

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    int randomNumber= arc4random() % 3;
    NSIndexPath *indexPath = [tableview indexPathForSelectedRow];

    if ([segue.identifier isEqualToString:@"randomsegue"]){
        if (randomNumber==0){
            //navigate to first view controller
        }
        else if(randomNumber==1){
            //navigate to second view controller
        }
        else{
            //navigate to third view controller
        }
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • This must be a duplicate question, so I'm not going to post an answer yet. But the basic idea is to wire the button to an IBAction instead of a segue, and invoke the correct segue in code using performSegueWithIdentifier instead. – Mike Mertsock May 13 '14 at 12:13
  • use this link http://stackoverflow.com/questions/23102978/swrevealviewcontroller-without-using-navigationcontroller/23105142#23105142 – Anbu.Karthik May 13 '14 at 12:16

2 Answers2

1

check this , i think what you want is similar to this.

-(IBAction)buttonAction:(id)sender{

int randomNumber= arc4random() % 3;

switch (randomNumber) {
    case 0:
         [self performSegueWithIdentifier:@"segue1" sender:sender];
        break;
    case 1:
         [self performSegueWithIdentifier:@"segue2" sender:sender];
        break;
    case 2:
         [self performSegueWithIdentifier:@"segue3" sender:sender];
        break;
    default:
        break;
}

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

if ([segue.identifier isEqualToString:@"segue1"])
{
    //navigate to view controller 1
}
else if ([segue.identifier isEqualToString:@"segue2"])
{

    //navigate to view controllr 2
}
else{

    //navigate to view controller 3
 }
}
Pawan Rai
  • 3,434
  • 4
  • 32
  • 42
0

Set up all the possible seques with identifiers and then set up a IBAction with the appropriate identifier in your switch statement.

Dean Davids
  • 4,174
  • 2
  • 30
  • 44