Reputation: 81
I am creating a game that ends when the timer is up and a new end game view appears I have not been able to get the view to switch to the next view in the story board when time expires, all that appears is a black screen. This is the code where it switches view controllers
- (void)subtractTime {
// 1
seconds--;
timerLabel.text = [NSString stringWithFormat:@"Time: %i",seconds];
// 2
if (seconds == 0) {
[timer invalidate];
GamerOverViewController *gamerOverViewController = [[GamerOverViewController alloc] init];
[self presentViewController:gamerOverViewController animated:YES completion:nil];
}
}
and this is the code in the new view controller where I am trying to make a view with a label appear:
- (IBAction)goNext:(id)sender
{
[self performSegueWithIdentifier:@"pushTo10" sender:self];
}
Thanks for any help in getting this to work.
Upvotes: 0
Views: 60
Reputation: 2256
Try use [[UIStoryBoard stroyBoardWithName:@"MainStoryboard] instantiateViewControllerWithIdentifier:@"GamerOverViewController"]
to instantiate the GamerOverViewController
instead of using alloc init
. Remember you have to set the identifier in storyboard
Upvotes: 1
Reputation: 62062
In order to present a view using presentViewController:animated:completion:
, you must initWithNibName:
rather than just init
. The viewController
you're presenting has to know what nib to load (and then control) when it's pushed.
Better is to just use segues.
if(seconds==0) {
[timer invalidate];
[self performSegueWithIdentifier:@"whateverYourSegueIsNamed" sender:self];
}
Upvotes: 1