2012-12-15 53 views
1

應該是一個簡單的解決方案,我很想念。我有一個Tab View Controller驅動的應用程序,我希望在用戶啓動或打開應用程序時對其進行密碼保護。我在IB中創建了一個密碼類&視圖控制器。@ AppDelegate.m中的接口錯誤類

我試圖使用AppDelegate.m類applicationDidLoadInForeground方法用下面的代碼:

- (void)applicationWillEnterForeground:(UIApplication *)application 
{ 
    NSUserDefaults *submissionDefaults = [NSUserDefaults standardUserDefaults]; 
    if ([submissionDefaults boolForKey:@"passcodeActive"] == true) 
    { 
     PINAuthViewController *pinController = [[PINAuthViewController alloc] init]; 
     [self presentViewController:pinController animated:YES completion:nil]; 
    } 
} 

我已經導入我的PINAuthViewController類在頭

#import "PINAuthViewController.h" 

但是我收到一個錯誤當編譯「AppDelegate沒有可見的@interface」聲明選擇器'presentViewController:animated:completion'。

任何人都可以提醒我做錯了什麼?如果密碼輸入正確,則意圖解除密碼「視圖控制器」。

非常感謝,詹姆斯

回答

10

應用程序的委託不能因爲它不是自己的UIViewController的一個子類呈現視圖控制器。

您需要更改您的代碼:

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

你缺少在方法調用某些重要文本。 – rmaddy

+0

糟糕,固定!感謝您的高舉。 –

+0

謝謝!我的代碼現在編譯,但是當我運行它時,視圖在執行時變黑。在xcode中引發以下警告: 警告:嘗試在上顯示其視圖不在窗口層次結構中的! 有關如何解決此問題的更多建議?謝謝! – JamesLCQ

1

你也可以試試這個代碼...

self.viewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; 
self.window.rootViewController = self.viewController; 
[self.window makeKeyAndVisible];