Xcode-编码 Segue 期间的 EXC_BAD_ACCESS
在我的应用程序中,当满足特定条件时,我尝试在代码中编写一个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];
}
在我的 Storyboard 中有一个带有标识符“menu”的模态 Segue。
我发现的关于该主题的其他几篇文章主要回答了与内存管理相关的解决方案。我在 IOS 5 上使用 ARC,所以我认为这不是问题。非常感谢所有帮助,我可以发布任何其他可能有帮助的代码。
In my app, I am trying to program a segue in code when a specific condition is met. I call the segue using [self performSegueWithIdentifier:Sender]. This is called in an IBAction, which is called by pressing a UIButton. However, I get the EXC_BAD_EXCESS error message. The actual error message is attached to a different line of code, but I think it is still referring to the segue based on what happened when the segue was commented out. Through NSLogging, I do know that the IBAction is indeed being called by the button.
The method in which the Button is created:
- (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");
}
Then the mainMenuSegue that is called:
- (IBAction)mainMenuSegue {
[self performSegueWithIdentifier:@"menu" sender:self];
}
There is a modal segue in my storyboard with the identifier "menu."
The couple other posts on the subject I found were mainly answered with solutions pertaining to memory management. I am using ARC with IOS 5 so I do not think this is the issue. All help is very much appreciated, and I can post any other code which might help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你想要这个,
我认为
self
没有你认为的上下文I think you want this
I dont think
self
has the context you think it does