如何在应用程序委托iOS10的applicationWillEnterForeground方法中呈现模态UIViewController目标C

问题描述:

我想在进入前台应用程序时提供一个UIViewController。
我在Objective C appDelegate应用程序中使用此代码applicationWillEnterForeground方法,但它不适用于我。如何在应用程序委托iOS10的applicationWillEnterForeground方法中呈现模态UIViewController目标C

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
PasscodeViewController *vc = [sb instantiateViewControllerWithIdentifier:@"passcodeVCID"]; 
[self presentViewController:vc animated:YES completion:nil]; 
+0

那你估计是'里面的appDelegate self'? – NSNoob

+0

我以前在uiviewcontroller中使用SELF。有作品。但我不知道如何在这里处理它。 –

+0

这是因为在UIViewController类中,self是一个ViewController。 'presentViewController'是一个在UIViewController.h中定义的方法,所以它在那里工作。在AppDelegate中,self是AppDelegate,它没有名为'presentViewController'的方法。 – NSNoob

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
PasscodeViewController *vc = [sb instantiateViewControllerWithIdentifier:@"passcodeVCID"]; 

// Need to present with rootviewcontroller 

[self.window.rootViewController presentViewController:vc animated:YES completion:nil]; 
+0

我用这个代码到applicationWillEnterForeground方法中,但它不起作用。 –

+0

尝试一次 [self.window.rootViewController.navigationController presentViewController:vc animated:YES completion:nil]; – Bucket