【问题标题】:Launch main ViewController when home button is pressesd按下主页按钮时启动主 ViewController
【发布时间】:2016-01-26 22:24:00
【问题描述】:

我正在做一个具有多个独立 ViewControllers 的 Objective-C 应用程序。 当用户按下主页按钮并且应用程序进入后台模式时,我想显示我的主 ViewController。 我发现的所有解决方案都适用于导航控制器。 在这种情况下,我如何启动(以及在哪里) ViewController?

谢谢

已解决: 最后我在 AppDelegate 中添加解决了这个问题:

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

    ViewController *viewController=[[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController"];
    self.window.rootViewController = viewController;
}

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

    您应该在主视图控制器中注册UIApplicationDidEnterBackgroundNotification。发布通知后,您应该将导航堆栈弹出到主视图控制器。

    [self.navigationController popToRootViewControllerAnimated:YES];
    

    或者,如果这不是您应该使用的根视图控制器:

    [self.navigationController popToViewController:self animated:YES];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多