我有一个UIPickerView
,有5个不同的对象,还有一个按钮。当我按下按钮时,我想转到下一个ViewController。
例如:当我在Options
中选择UIPickerView
并按下按钮时,我想转到OptionsViewController ...我尝试使用switchCase,但它对我不起作用。在switchCase里面,我把:
[self performSegueWithIdentifier:@"goToOptions" sender:nil];
我现在的问题是:如何连接viewcontrollers以及如何调用此viewcontroller开关?
完整的switchCase是:
switch (rowSelected) {
case Start_Game:
[self performSegueWithIdentifier:@"goToGame" sender:sender];
break;
case Scores:
[self performSegueWithIdentifier:@"goToScores" sender:sender];
break;
case How_To_Play:
[self performSegueWithIdentifier:@"goToHTP" sender:sender];
break;
case Options:
[self performSegueWithIdentifier:@"goToOptions" sender:sender];
break;
case About:
[self performSegueWithIdentifier:@"goToAbout" sender:sender];
break;
default:
break;
答案 0 :(得分:0)
做这样的事......
-(IBAction)btnClickMethod:(id)sender
{
NSString *identifier;
switch(cases)
case 0:
identifier=@"abc"; //set this identifier as per your case and condition
break;
case 1:
identifier=@"def"; //set this identifier as per your case and condition
break;
default
identifier=@"ghi" //set this identifier as per your case and condition
break;
[self performSegueWithIdentifier:identifier sender:sender];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"abc"])
{
// Get reference to the destination view controller
YourViewController *vc = [segue destinationViewController];
// Pass any objects to the view controller here, like...
[vc setMyObjectHere:object];
}
if ([[segue identifier] isEqualToString:@"def"])
{
// Get reference to the destination view controller
YourViewController *vc = [segue destinationViewController];
// Pass any objects to the view controller here, like...
[vc setMyObjectHere:object];
}
等......取决于开关中的案例数