0

我最近为我的应用程序编写教程。我使用本教程创建了教程:

http://www.appcoda.com/uipageviewcontroller-tutorial-intro/

我创建了一个“按钮”,将用户带回到rootViewController. 在本例中为TabBarController. 问题是:在本教程中,我为教程制作了一个额外的故事板。rootViewController(TabBarController)那么我怎样才能用按钮回到原来的状态呢?

代码:

- (IBAction)start:(id)sender {
        UIViewController* backToRootViewController = [[UIViewController alloc] initWithNibName:@"TabBarController" bundle:[NSBundle mainBundle]];
        [self.view addSubview:backToRootViewController.view];
}

这也行不通

- (IBAction)start:(id)sender {
           [self.navigationController popToRootViewControllerAnimated:YES];
    }

编辑

在第一次开始时打开教程:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
BOOL isAccepted = [standardUserDefaults boolForKey:@"iHaveAcceptedTheTerms"];
if (!isAccepted) {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.viewController = [[APPViewController alloc] initWithNibName:@"APPViewController" bundle:nil];
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
}

APPViewController是教程

编辑

在 johnnelm9r 的帮助下,当前代码是这样的:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"main" bundle: nil];

    IntroViewController *introViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"IntroViewController"];

        BOOL isAccepted = [standardUserDefaults boolForKey:@"iHaveAcceptedTheTerms"];
        if (!isAccepted) {
            [self.window.rootViewController presentViewController:introViewController animated:NO completion:nil];
        }

但是现在,可悲的是,应用程序崩溃了,错误是:

Application tried to present a nil modal view controller on target <UITabBarController: 0x175409d0>.'

还有一个警告:Incompatible pointer type assigning to 'ViewController' from 'UIViewController' in AppDelegate

4

2 回答 2

0

*****更新****

我上传了一个示例项目来说明我的意思。你可以在这里找到它:github链接 祝你好运!

**** 编辑

在与您讨论更多之后,我建议尝试在您的 viewDidAppear 方法中使用类似于此代码的代码,无论视图控制器运行您的 tabbarcontroller 的第一个选项卡(显然您想要您自己的类名,其中我有 IntroViewController):

BOOL didShowIntro = [[NSUserDefaults standardUserDefaults] boolForKey:@"showIntro"];

IntroViewController *introViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"IntroViewController"];

if (didShowIntro)
    {
    [self presentViewController:introViewController animated:NO completion:nil];
    }

然后只需从教程中的按钮中弹出显示的控制器,如下所示:

[self dismissViewControllerAnimated:NO completion:nil];

当您按下教程视图控制器中的按钮时,请记住将您的用户默认设置为 no。并确保您从 tabbarcontroller 到 navigationcontroller 作为关系 segue,然后到要在教程之后作为 root 显示的视图控制器。需要明确一点:故事板上的教程视图控制器不应该有任何连接。

更清楚一点:您的故事板应该将导航栏控制器作为您的初始视图控制器连接到连接到视图控制器的导航控制器和另一个未连接到任何东西的视图控制器。:) 并确保删除委托中的代码。

于 2014-04-29T19:24:55.373 回答
0

去 rootViewController

[self.navigationController popToRootViewControllerAnimated:YES];
于 2014-04-30T04:30:27.440 回答