Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 按下“主页”按钮时启动主ViewController_Ios_Objective C - Fatal编程技术网

Ios 按下“主页”按钮时启动主ViewController

Ios 按下“主页”按钮时启动主ViewController,ios,objective-c,Ios,Objective C,我正在做一个Objective-C应用程序,它有几个独立的ViewController。 我想显示我的主视图控制器时,用户脉冲主页按钮和应用程序进入后台模式。 我找到的所有解决方案都是针对导航控制器的。 在这种情况下,如何启动(以及在何处启动)ViewController 谢谢 已解决: 最后,我通过添加AppDelegate解决了这个问题: - (void)applicationWillEnterForeground:(UIApplication *)application { //

我正在做一个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;
}

您应该在主viewcontroller中注册
UIApplicationIdentinterBackgroundNotification
。发布通知后,应将导航堆栈弹出到主viewcontroller

[self.navigationController popToRootViewControllerAnimated:YES];
或者,如果这不是根viewcontroller,则应使用:

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