1

Im a new programmer and I am stuck with a problem. I simply want to transit from ViewController to NOViewController when the livesLeft reaches to 0.

(When you're dead, the "death"screen should appear) Big thanks in advance!

if (livesLeft == 0)
{
    //transit to NOViewController

}
Black Frog
  • 11,595
  • 1
  • 35
  • 66
MrHaze
  • 43
  • 6

3 Answers3

0

Do you meant this?

NOViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:@"storyboard_identifier"];

[self.navigationController pushViewController:secondView animated:YES];
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
0

Yeah kinda! Im really a newbie so haven't learned about navigation controller yet. But this solved my problem:

{
     NOViewController *NOVC = [[NOViewController alloc]init];
    [self presentViewController:NOVC animated:YES completion:^{

    }];

Many thanks for your reply!

MrHaze
  • 43
  • 6
  • Are you going to let the user go back to the game from the game over screen? If so, will you reuse the previous view controller or present a new one? – Andrew Monshizadeh Jan 05 '15 at 14:11
  • Yes thats right. I will reuse the same view controller! Actually, the game over screen is also shown from the Start screen, if you click the "NO, I don't dare to play."-button. On the "game over VC" I added a button so you could go back to the "start screen VC" But when I transit from the "game view controller" to "game over VC" the "go back" button i gone?! – MrHaze Jan 05 '15 at 14:25
  • It definitely sounds like you would be better served using a navigation controller. Your setup sounds like you want a root view controller of the Start view controller. Then you could push on the game view controller. The view controller stack would then be [Start, Game]. When the game ends, you could put the game over view controller into the stack under the top view controller. The view controller stack would then be [Start, Game Over, Game]. Then you would pop the top view controller. The view controller stack would then be [Start, Game Over]. – Andrew Monshizadeh Jan 05 '15 at 15:44
  • Aha, I´ll have to do my homework on navigation controllers then.. Does navigation controller always show it self with a bar at the top of the screen or is it possible to have one working in the background? – MrHaze Jan 05 '15 at 15:59
  • It is possible to set the navigation bar to hidden using `- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated`. – Andrew Monshizadeh Jan 06 '15 at 02:52
0
if (livesLeft == 0)
{
    NOViewController *NoLivesVC = [[UIStoryBoard storyboardWithName: @"Main" setBundle: nil] instantiateViewConrollerWithIdentifier: @"ViewControllerIndentifier"];
    // Do something
    [self presentViewController animated: YES completion:nil];

}

Hope this helps. I presume this is what you were asking.

Awais Hussain
  • 2,400
  • 2
  • 12
  • 11
  • Thanks for reply! It won't build and I get the wrong message: "Expected identifier" on this part: @"ViewControllerIndentifier"]; any ideas? – MrHaze Jan 05 '15 at 14:40
  • This could be because you are not changing the View Controller's identifier, or the both do not match. You have to go to the storyboard and select the view controller you wish to display. Then on the Right hand side panel select the "Identity Inspector" and changee the "Storyboard ID" and "Restoration ID" to your preferred identifier. For the code above you would change it to ViewControllerIndentifier – Awais Hussain Jan 07 '15 at 13:06