I have the following code:

In 1 class (GamePlay1) I have method that change view controller if game ends:

 -(void)end
 {
   [self performSegueWithIdentifier:@"menu1" sender:self];
 }

In 2 SKView class i have a method that calls function in 1 class to change view controller:

 -(void)gameEnded
 {
     GamePlay1 *gp1 = [[GamePlay1 alloc]init];
     [gp1 end];
 }

I get the warning:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<GamePlay1: 0x156329e0>) has no segue with identifier 'menu1''

I tried to change seque name for few times, also I tried to clean my project, deleting app and installing again, but the result is the same.

有帮助吗?

解决方案

The segue is defined in a storyboard, when instantiating the class manually with alloc and init, the controller has no reference to the IB object, therefore no segue is defined. You want to use the storyboard itself to instantiate your controller:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
GamePlay1 *controller = [storyboard instantiateViewControllerWithIdentifier:@"GamePlay1"];
[controller end];

Please note that this is not the proper way of doing a segue, you need to obtain a reference to the current instantiated viewcontroller instead of creating a new one.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top