2012-01-15 64 views
0

在我的应用程序中,我试图在满足特定条件时编写代码中的segue。我使用[self performSegueWithIdentifier:Sender]呼叫segue。这在IBAction中调用,通过按UIButton来调用它。但是,我收到了EXC_BAD_EXCESS错误消息。实际的错误消息被附加到不同的代码行,但我认为它仍然是基于当segue被注释掉时发生的事情来引用segue。通过NSLogging,我知道IBAction确实被按钮调用。Xcode- EXC_BAD_ACCESS在编码塞格期间

在其中创建按钮的方法:

- (void)gameOver { 
[run invalidate]; 
[xViewTimer invalidate]; 
[gameTimer invalidate]; 

gameOverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
gameOverView.backgroundColor = [UIColor blueColor]; 


CGRect f = CGRectMake(0, 20, 320, 100); 

scoreIs = [[UILabel alloc] initWithFrame:f]; 
scoreIs.textAlignment= UITextAlignmentCenter; 
scoreIs.adjustsFontSizeToFitWidth = YES; 
scoreIs.backgroundColor = [UIColor clearColor]; 
scoreIs.font = [UIFont systemFontOfSize:26]; 
[scoreIs setText:@"You Finished With A Score Of:"]; 

UILabel *showPoints = [[UILabel alloc] initWithFrame:CGRectMake(0, 80, 320, 100)]; 
showPoints.textAlignment = UITextAlignmentCenter; 
showPoints.adjustsFontSizeToFitWidth = YES; 
showPoints.backgroundColor = [UIColor clearColor]; 
showPoints.font = [UIFont systemFontOfSize:50]; 
[showPoints setText:[NSString stringWithFormat:@"%d", points]]; 

UIButton *playAgainButt = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
playAgainButt.frame = CGRectMake(self.view.center.x-70, 200, 140, 50); 
[playAgainButt setTitle:@"Play Again" forState:UIControlStateNormal]; 
[playAgainButt addTarget:self action:@selector(newGame) forControlEvents:UIControlEventTouchUpInside]; 

UIButton *toMain = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
toMain.frame = CGRectMake(self.view.center.x-70, 280, 140, 50); 
[toMain setTitle:@"Main Menus" forState:UIControlStateNormal]; 
[toMain addTarget:self action:@selector(mainMenuSegue:) forControlEvents:UIControlEventTouchUpInside]; 

scoreIs.hidden = NO; 

[gameOverView addSubview:toMain]; 
[gameOverView addSubview:playAgainButt]; 
[gameOverView addSubview:showPoints]; 
[gameOverView addSubview:scoreIs]; 
[self.view addSubview:gameOverView]; 

NSLog(@"Game Over"); 
} 

那么这就是所谓的mainMenuSegue:

- (IBAction)mainMenuSegue { 
    [self performSegueWithIdentifier:@"menu" sender:self]; 
} 

有一个在我的故事板与标识符模态SEGUE“菜单”。

我发现这个话题的其他文章主要回答有关内存管理的解决方案。我使用IOS 5与ARC,所以我不认为这是问题。所有帮助非常感谢,我可以发布任何其他可能有用的代码。

回答

0

我想你想这

- (IBAction)mainMenuSegue:(id)sender { 
    [self performSegueWithIdentifier:@"menu" sender:sender]; 
} 

我不认为self有你认为它

+0

感谢您的答复的情况下。但我试过这个,得到了同样的回应。也许有其他想法吗? – user1110415 2012-01-15 23:25:12

+0

你不得不提供更多的代码来进一步调试 – cpjolicoeur 2012-01-16 02:27:32

+0

我增加了一些代码。问题可能是故事板中的segue本身吗?这是一个视图控制器与另一个视图控制器之间的模式延续。它是否必须是某种对象到另一个视图控制器?我得到了错误:Receiver()没有带标识符'menu'的segue。但我知道有一个赛格,这导致我相信它以某种方式错误类型的赛格。 – user1110415 2012-01-16 17:42:32