我有一个应用程序我有一段时间没碰过,并决定更新它。当我在 Xcode 4.6 中运行它时,我得到一个 Bad Access 错误,当我分析它时,我的 ViewController Alertview 是被调用并最终作为 NSZombie 留下的对象。
我不确定问题是警报视图还是它调用的视图控制器。
这是与调用警报视图的按钮相关联的操作:
- (IBAction)newGame:(id)sender {
timerIsActive = NO;
//UIImage *pauseImage = [UIImage imageNamed:rndImage];
UIImageView *pauseView = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)] autorelease];
pauseView.image = gameImage;
[self.view addSubview:pauseView];
NSString *message = [NSString stringWithFormat:@"Would you like to reset the game?"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New Game"
message:message
delegate:self
cancelButtonTitle:@"Back to Game"
otherButtonTitles:@"New Game", nil];
[alert show];
[alert release];
[Flurry logEvent:@"New Game"];
}
警报视图如下:
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
timerIsActive = NO;
NSString *buttonString = [actionSheet buttonTitleAtIndex:buttonIndex];
if( [buttonString isEqualToString:@"Main Menu"] ){
[self.view removeFromSuperview];
} else if( [buttonString isEqualToString:@"View Board"] ){
} else if( [buttonString isEqualToString:@"Back to Game"] ){
timerIsActive = YES;
NSArray *arr =[self.view subviews];
[[[self.view subviews] objectAtIndex:([arr count]-1)] removeFromSuperview];
} else if( [buttonString isEqualToString:@"New Game"] ){
seconds = 120;
board.numOfLetters = 0;
board.currentWordLetters = nil;
board.currentString = nil;
board.words = nil;
board.letters = nil;
//[boardView release];
//[board release];
[timer invalidate];
[self release];
ViewController *viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
viewController.gameSize = self.gameSize;
self.view = viewController.view;
}