【问题标题】:How can you make a new Storyboard View Appear Without a Button如何在没有按钮的情况下显示新的 Storyboard 视图
【发布时间】:2013-12-11 02:07:48
【问题描述】:

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

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

感谢您为使其正常工作提供的任何帮助。

【问题讨论】:

  • 是否使用 segues。请不要半途而废。

标签: ios


【解决方案1】:

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

最好只使用segues。

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

【讨论】:

  • @user1828081 您需要将“whateverYourSegueIsNamed”替换为故事板上您的 segue 实际命名的内容。您没有为我提供足够的信息来实际诊断异常,但是,它几乎肯定是在说“不存在带有标识符的 segue...”
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-22
    • 2016-04-24
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    相关资源
    最近更新 更多