如何在没有按钮的情况下显示新的故事板视图

时间:2013-12-11 02:07:49

标签: ios

我正在创建一个游戏,当计时器启动并且出现新的结束游戏视图时结束我无法在时间到期时让视图切换到故事板中的下一个视图,所有出现的都是黑屏。这是切换视图控制器的代码

- (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];
    }
}

这是新视图控制器中的代码,我正在尝试使用标签创建视图:

- (IBAction)goNext:(id)sender
{
    [self performSegueWithIdentifier:@"pushTo10" sender:self];
}

感谢您帮助我们开展此工作。

2 个答案:

答案 0 :(得分:1)

要使用presentViewController:animated:completion:呈现视图,您必须initWithNibName:而不仅仅是init。您呈现的viewController必须知道在推动时加载(然后控制)的笔尖。

更好的是只使用segues。

if(seconds==0) {
    [timer invalidate];
    [self performSegueWithIdentifier:@"whateverYourSegueIsNamed" sender:self];
}

答案 1 :(得分:1)

尝试使用[[UIStoryBoard stroyBoardWithName:@"MainStoryboard] instantiateViewControllerWithIdentifier:@"GamerOverViewController"]来实例化GamerOverViewController,而不是使用alloc init。请记住,您必须在故事板中设置标识符

相关问题