如何在不知道谁呈现 UIActionSheets 和 UIPopoverControllers 的情况下关闭它们
在我的客户端应用程序中,我有一个空闲超时控制机制,当用户在指定的时间间隔内没有对应用程序执行任何操作时,我会显示一条警告并将其返回登录屏幕。此控件发生在我的容器视图中,我在其中启动所有其他视图。当空闲时间结束时,我将这个容器视图弹出给它的调用者,即登录屏幕。
问题是,如果用户执行显示操作表或弹出窗口的操作,然后在空闲时间结束之前不执行任何操作,那么当我将他扔到登录屏幕时,操作表和弹出窗口也会保留在登录屏幕上因为我不会解雇他们。
为了解决这个问题,我可以考虑让所有操作表和弹出窗口保留我的视图控制器的成员,然后在其所有者的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会注册 UIPopover 实例来监听一些通知。
并向 UIPopover 类添加扩展。
当我需要关闭弹出窗口时,我只需要发布通知即可。
I would register the UIPopover instance to listen to some notification.
And add extension to UIPopover class.
When I need to dismiss popover, I just need to post notification.
当我们在问题评论中与 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.