在我的应用中,我正在尝试在满足特定条件时在代码中编写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];
}
我的故事板中有一个带有标识符“menu”的模态segue。
我找到的关于这个主题的其他几个帖子主要回答了与内存管理有关的解决方案。我正在使用ARC和IOS 5,所以我不认为这是问题所在。非常感谢所有帮助,我可以发布任何其他可能有帮助的代码。
答案 0 :(得分:0)
我想你想要这个
- (IBAction)mainMenuSegue:(id)sender {
[self performSegueWithIdentifier:@"menu" sender:sender];
}
我不认为self
有您认为的上下文