如何在不知道谁呈现 UIActionSheets 和 UIPopoverControllers 的情况下关闭它们

发布于 2024-11-24 00:33:19 字数 395 浏览 2 评论 0原文

在我的客户端应用程序中,我有一个空闲超时控制机制,当用户在指定的时间间隔内没有对应用程序执行任何操作时,我会显示一条警告并将其返回登录屏幕。此控件发生在我的容器视图中,我在其中启动所有其他视图。当空闲时间结束时,我将这个容器视图弹出给它的调用者,即登录屏幕。

问题是,如果用户执行显示操作表或弹出窗口的操作,然后在空闲时间结束之前不执行任何操作,那么当我将他扔到登录屏幕时,操作表和弹出窗口也会保留在登录屏幕上因为我不会解雇他们。

为了解决这个问题,我可以考虑让所有操作表和弹出窗口保留我的视图控制器的成员,然后在其所有者的 viewWillDisappear 方法上将其解雇。但我有很多视图控制器,所以我正在寻找其他方法(如果有的话)。

因此,问题是如何在不知道呼叫者是谁的情况下使所有这些操作表和弹出窗口从我的登录屏幕消失?

In my client application I have an idle timeout control mechanism and when the user does not do anything with the app for a specified time interval, I display a warning and throw him back to the login screen. This control happens in my container view where I initiate all of my other views. When the idle time is up, I pop this container view to its caller, i.e the login screen.

The problem is, if the user does sthg that displays an action sheet or a popover and then does not do anything until the idle time is up, when I throw him to the login screen the action sheets and the popovers also remain on the login screen since I don't dismiss them.

To solve this, I can think of making all the action sheets and the popovers retained members of my view controllers and then dismissing them on the viewWillDisappear methods of their owners. But I have so many view controllers, so I'm looking for other ways, if there are any.

So, the question is how can I make all these action sheets and popovers go away from my login screen without knowing who their callers are?

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

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

发布评论

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

评论(2

断舍离 2024-12-01 00:33:19

我会注册 UIPopover 实例来监听一些通知。

[[NSNotificationCenter defaultCenter] addObserver:_myPopOver 
                                         selector:@selector(myDismissPopover)
                                             name:@"dismissPopover" 
                                           object:nil];

并向 UIPopover 类添加扩展。

- (void) myDismissPopover {
 [self dismissPopoverAnimated:YES];
}

当我需要关闭弹出窗口时,我只需要发布通知即可。

[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissPopover" 
                                                    object:nil];

I would register the UIPopover instance to listen to some notification.

[[NSNotificationCenter defaultCenter] addObserver:_myPopOver 
                                         selector:@selector(myDismissPopover)
                                             name:@"dismissPopover" 
                                           object:nil];

And add extension to UIPopover class.

- (void) myDismissPopover {
 [self dismissPopoverAnimated:YES];
}

When I need to dismiss popover, I just need to post notification.

[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissPopover" 
                                                    object:nil];
故人如初 2024-12-01 00:33:19

当我们在问题评论中与 bshirley 交谈时,我将写下我自己的解决方案。
我已经实现了这样的机制来解决这个问题:

在我的登录视图控制器中,我创建一个 NSMutableArray ,它将保留所有将被关闭的操作表和弹出窗口控制器。然后我将这个数组存储在全局字典中。我通过实用方法访问这本字典。然后在整个应用程序中,无论谁创建了操作表或弹出窗口控制器,都将组件添加到该数组中(从全局数据中检索该数组,修改它,然后将其保存回全局数据)。然后,当用户返回到登录屏幕时,在我的登录视图控制器的 viewWillDisappear 中,我循环遍历该数组,并通过检查从数组中获取的 UIView 是操作表还是弹出窗口控制器来调用适当的解雇方法。然后我删除该数组的所有元素,然后再次将其存储回全局数据中。

希望这可以帮助任何需要实施类似机制的人。我们将不胜感激您的意见。

I'll write down my own solution as we've talked with bshirley in the comments of the question.
I've implemented a mechanism like this to solve the problem:

In my login view controller, I create an NSMutableArray that will keep all my action sheets and popover controllers that are going to be dismissed. Then I store this array in a global dictionary. I access this dictionary via a utility method. Then all through the application, whoever creates an action sheet or a popover controller, adds the component to this array (retrieves the array from the global data, modifies it and then saves it back to the global data). Then when the user is thrown back to the login screen, in viewWillDisappear of my login view controller, I loop through this array and call the appropriate dismiss method by checking if the UIView I get from the array is an action sheet or a popover controller. Then I remove all the elements of this array and then store it back in the global data, again.

Hope this helps anyone who needs to implement a similar mechanism. Your comments will be appreciated.

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