2013-03-23 54 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

相關問題