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