Transit between view controllers using code

176 Views Asked by At

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

}
3

There are 3 best solutions below

2
On BEST ANSWER
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.

5
On

Do you meant this?

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

[self.navigationController pushViewController:secondView animated:YES];
5
On

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!