模态视图中的密码 ViewController 演示

发布于 2024-12-12 05:20:42 字数 736 浏览 0 评论 0原文

我正在我的 iPhone 应用程序中实现密码功能,该应用程序有一个 UITabBarController 作为根视图控制器。在大多数情况下,我的一切都工作得很好,当应用程序进入后台时,通过从 tabBarController 显示模态 Passcode ViewController,如下所示:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    if ([[NSUserDefaults standardUserDefaults] valueForKey:kPasscodeStringKey]) {

        PasscodeEntryVC *passcodeView = [[PasscodeEntryVC alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:passcodeView];
        [tabBarController presentModalViewController:nav animated:NO];
    }
}

当应用程序进入后台时已经显示模态视图控制器时,我的问题就出现了。然后,不会出现密码视图。这样做的正确方法是什么?我是否应该首先检查当前视图是什么,然后显示密码,而不是仅仅将消息发送到 tabBarController 来显示视图?如果是这样,这是如何完成的?谢谢。

I'm implementing a Passcode feature in my iPhone app which has a UITabBarController as a root view controller. I have everything working great in most situations, by displaying a modal Passcode ViewController from the tabBarController when the app goes into the background, like so:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    if ([[NSUserDefaults standardUserDefaults] valueForKey:kPasscodeStringKey]) {

        PasscodeEntryVC *passcodeView = [[PasscodeEntryVC alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:passcodeView];
        [tabBarController presentModalViewController:nav animated:NO];
    }
}

My problem comes when the app is already displaying a modal view controller when it enters the background. Then, no passcode view appears. What would be the correct way to do this? Instead of just sending the message to the tabBarController to present the view, should I be checking first to see what the current view is, then have that present the passcode? If so, how is this done? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

唐婉 2024-12-19 05:20:42

首先 - 您正在泄漏内存,因为您没有释放您的passcodeView和导航控制器nav

其次 - 您可以保留一个简单的 BOOL 变量,每当呈现或关闭模态视图时都会更新该变量。如果有模态视图,只需在 applicationDidEnterBackground: 方法中调用 dismissModalViewController:animated: 即可。

您还可以使用 [self.navigationController.topViewController class] 检查最前面的视图控制器,但我发现这是不可靠的。

First - you are leaking memory because you do not release your passcodeView and navigation controller nav.

Second - you could keep a simple BOOL variable that is updated whenever a modal view is presented or dismissed. If there is a modal view, just call dismissModalViewController:animated: in your applicationDidEnterBackground: method.

You could also check the frontmost view controller with [self.navigationController.topViewController class], but I have found this to be unreliable.

笔芯 2024-12-19 05:20:42

我通常做的是确保我拥有的任何可能呈现模态视图控制器的视图,以便在发送 UIApplicationWillResignActiveNotification 通知时关闭模态视图控制器,而在我的应用程序委托中,我设置它和你的一模一样。

但需要注意的是,每当您关闭上述模态视图控制器时,您都需要确保在提供密码视图控制器之前将 animated: 设置为 NO 来关闭它们。

What I usually do is to ensure that any views I have that may present a modal view controller to dismiss the modal view controller whenever it is sent the UIApplicationWillResignActiveNotification notification, while over in my app delegate, I set it up exactly like yours.

One caveat though, is that whenever you dismiss the said modal view controllers, you need to ensure that you dismiss them with animated: set to NO before presenting your passcode view controller.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文