无法从AppDelegate调用锁屏视图控制器

时间:2013-03-04 04:58:39

标签: ios xcode locking lockscreen appdelegate

我已经实现了KKLockscreen视图控制器,并且在应用内设置控制器中运行良好。能够设置密码并改变它们。

我有问题从appdelegate调用他锁定屏幕视图。我添加了委托.h文件并在.m文件中导入了视图控制器。仍然没有调用锁屏。任何帮助?

下面是我的代码。

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    if ([[KKPasscodeLock sharedLock] isPasscodeRequired]) {
        KKPasscodeViewController *vc = [[KKPasscodeViewController alloc] initWithNibName:nil bundle:nil];
        vc.mode = KKPasscodeModeEnter;
        vc.delegate = self;

        dispatch_async(dispatch_get_main_queue(),^ {
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];

            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
                nav.modalPresentationStyle = UIModalPresentationFormSheet;
                nav.navigationBar.barStyle = UIBarStyleBlack;
                nav.navigationBar.opaque = NO;
            } else {
                nav.navigationBar.tintColor = _navigationController.navigationBar.tintColor;
                nav.navigationBar.translucent = _navigationController.navigationBar.translucent;
                nav.navigationBar.opaque = _navigationController.navigationBar.opaque;
                nav.navigationBar.barStyle = _navigationController.navigationBar.barStyle;
            }

            [_navigationController presentModalViewController:nav animated:NO];
        });

    }
}

1 个答案:

答案 0 :(得分:0)

我已经用我的代码检查了它并且它正在工作,但是你没有在这一行给出笔尖名称,我已经给出了可能是为什么它没有显示你的视图。  KKPasscodeViewController * vc = [[KKPasscodeViewController alloc] initWithNibName:nil bundle:nil]

-(void)applicationDidBecomeActive:(UIApplication *)application {
RootViewController *vc = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];

dispatch_async(dispatch_get_main_queue(),^ {
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        nav.modalPresentationStyle = UIModalPresentationFormSheet;
        nav.navigationBar.barStyle = UIBarStyleBlack;
        nav.navigationBar.opaque = NO;
    } else {
        nav.navigationBar.tintColor = navigationController.navigationBar.tintColor;
        nav.navigationBar.translucent = navigationController.navigationBar.translucent;
        nav.navigationBar.opaque = navigationController.navigationBar.opaque;
        nav.navigationBar.barStyle = navigationController.navigationBar.barStyle;
    }

    [navigationController presentModalViewController:nav animated:NO];
});

}