0

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

创建 Button 的方法:

- (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]; 
}

我的故事板中有一个模态序列,标识符为“菜单”。

我发现的其他几篇关于该主题的帖子主要回答了与内存管理有关的解决方案。我在 IOS 5 中使用 ARC,所以我认为这不是问题。非常感谢所有帮助,我可以发布任何其他可能有帮助的代码。

4

1 回答 1

0

我想你想要这个

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

我不认为self有你认为的上下文

于 2012-01-15T19:38:59.090 回答