两个故事板之间的过渡 [英] Transition between 2 storyboards

查看:125
本文介绍了两个故事板之间的过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有2个故事板文件,我想在一个ViewController和另一个ViewController之间进行转换。我已经连接了一个IBAction,以响应第一个ViewController上的按钮按下,该控件调用AppDelegate中的方法。我已经验证此信号到达AppDelegate方法。

I have 2 storyboard files in my app and I'd like to transition between a ViewController in one to a ViewController in the other. I've hooked up an IBAction in response to a button press on the first ViewController, which calls a method in the AppDelegate. I have verified that this signal reaches the AppDelegate method.

这是我在AppDelegate中的相关方法,但是没有发生转换。有谁可以告诉我为什么,或者有2个故事板是一个愚蠢的想法?

Here is the relevant method I have in the AppDelegate, however, no transition occurs. Can anyone tell me why, or is it a silly idea to have 2 storyboards?

-(void) presentSecondViewController {

UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController* mainViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"main_viewcontroller"];

UIStoryboard* secondStoryboard = [UIStoryboard storyboardWithName:@"SecondStoryboard" bundle:nil];
UIViewController* secondViewController = [secondStoryboard instantiateViewControllerWithIdentifier:@"second_viewcontroller"];

[mainViewController presentViewController: secondViewController animated:YES completion: NULL];

}

推荐答案

您可以创建第一个故事板的初始视图控制器的第二个实例。该实例从未在屏幕上显示,因为它与已经显示的实例不同,因此可能不会显示您的第二个视图控制器。您需要已显示视图控制器的实例。最好的方法是将实现更改为

You create a second instance of the initial view controller of the first storyboard. That instance was never shown on the screen as it is different from the one being already shown and thus probably won't show your second view controller. You need the instance of the view controller already being shown. The best way would be to change your implementation to

-(void) presentSecondViewControllerFromViewController:(UIViewController *)sourceController
{
    UIStoryboard* secondStoryboard = [UIStoryboard storyboardWithName:@"SecondStoryboard" bundle:nil];
    UIViewController* secondViewController = [secondStoryboard instantiateViewControllerWithIdentifier:@"second_viewcontroller"];

    [sourceController presentViewController: secondViewController animated:YES completion: NULL];
}

并通过传递包含按钮的视图控制器来调用它。

and call it by passing the view controller that contains the button.

这篇关于两个故事板之间的过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆