2013-03-23 56 views
1

我有一款游戏,当您松动时,我试图回到主屏幕。当你松动时,这段代码会运行,但是当我在代码的末尾取消注释行时,它会在我尝试运行时给我一个错误。视图控制器和分类主屏幕和游戏是不同的。我在网上找不到任何可以工作的东西。使用代码切换视图控制器

-(void)resetAll { 
    [randomMain invalidate]; 

    CGRect frame = [player frame]; 
    frame.origin.x = 137.0f; 
    frame.origin.y = 326.0; 
    [player setFrame:frame]; 

    CGRect frame2 = [enemy frame]; 
    frame2.origin.x = 137.0f; 
    frame2.origin.y = 20.0; 
    [enemy setFrame:frame2]; 
    [NSObject cancelPreviousPerformRequestsWithTarget:self]; 
    [timerImageView stopAnimating]; 
    [email protected]""; 
    int sum = [lastRoundCash intValue] + [playerCash intValue]; 
    playerCash = [NSString stringWithFormat:@"%d", sum]; 
    [self performSelector:@selector(save) withObject:nil afterDelay:0]; 
    [self performSelector:@selector(updateLabelState) withObject:nil afterDelay:0]; 
    [freezeUseOutlet setHidden:true]; 

    int x = [lastRoundRound floatValue]; 
    int y = [highScore floatValue]; 

    if (x>y) { 
     highScore=lastRoundRound; 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New High Score!" message:[NSString stringWithFormat:@"You beat your high score! Your high score is now %@!",highScore] delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; 
     [alert show]; 
     [self performSelector:@selector(updateLabelState) withObject:nil afterDelay:0]; 
     [self.navigationController pushViewController:ViewController animated:YES]; 
    } 
} 
+0

我在代码中看不到注释行。 – 2013-03-23 18:58:52

回答

0

我想你想弹出视图控制器。

+0

错误信息是“Use of unidentified ViewController。Pop给出相同的错误 – user2201063 2013-03-23 20:48:34

+0

如果你使用pop,你不必给它一个视图控制器 – dasdom 2013-03-23 22:36:29

+0

[self.navigationController popViewController]; Error:No visible @interface 'UINavigationController'声明了选择器'popViewController'。用户通过按下一个按钮并通过简单的点击拖动到控制器来获得视图控制器,但我需要它切换回主屏幕,而不需要用户按下按钮 – user2201063 2013-03-23 22:44:29

相关问题