2016-11-08 29 views
0

我想在進入前臺應用程序時提供一個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

回答

0
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

相關問題