AppDelegate.m类中的@interface错误

Jam*_*LCQ 2 cocoa-touch objective-c ios appdelegate

应该是一个我想念的简单解决方案.我有一个Tab View Controller驱动的应用程序,我想在用户启动或打开应用程序时通过密码保护.我在IB中创建了一个密码类和视图控制器.

我正在尝试使用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];
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经在标头中导入了我的PINAuthViewController类

#import "PINAuthViewController.h"
Run Code Online (Sandbox Code Playgroud)

但是在编译"没有可见的@interface for'AppDelegate"声明选择器'presentViewController:animated:completion'时,我收到一个错误.

谁能告诉我我做错了什么?目的是在正确输入密码时关闭密码视图控制器.

非常感谢,詹姆斯

Hes*_*gid 11

app委托不能呈现视图控制器,因为它不是UIViewController本身的子类.

您需要将代码更改为:

[self.window.rootViewController presentViewController:pinController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

  • 我建议您将用于检查密码是否处于活动状态的逻辑移动到主视图控制器(应用程序启动后显示的那个),而不是应用程序委托.这应该可以解决您的问题. (2认同)