当 App 在 iOS4 上进入后台时关闭 UIActionSheet

发布于 2024-09-14 15:24:20 字数 983 浏览 8 评论 0原文

在我正在开发的应用程序中,我有操作表和警报视图,当应用程序进入非活动/后台状态时,我希望将其关闭。

我使用 UIApplicationWillResignActiveNotification 而不是 UIApplicationDidEnterBackgroundNotification,因为我希望代码与 iOS3.2 兼容。

-(void)applicationWillResignActive:(Notification *)notification{
    if (self.actionSheet && self.actionSheet.visible){
        NSLog(@" actionSheet is Visible");
        [self.actionSheet dismissWithClickedButtonIndex:0 animated:NO];
    }
}

在模拟器(iphone 3.2、iOS4)中测试这一点,在 actionSheet 可见的情况下,我按下主页按钮,但没有收到“actionSheet 可见”消息。然而,当我重新打开应用程序并使用主页按钮再次关闭它时,我收到“actionSheet 可见”消息。

这表明第一次没有设置actionSheet 的visible 属性。房产设置是否会延迟?事实上,我在显示 actionSheet 的方法中放置了一条消息,

[self.actionSheet showInView:self.parentViewController.tabBarController.view];
if (self.actionSheet.Visible) NsLog(@" action Sheet visible");

即使在这里我也没有收到该消息。可见属性在何处/何时设置?我在尝试忽略 actionSheet 时是否做了根本性错误?我已经看到类似的非常好的和详细的解决方案,关于在 SO.. 中忽略alertViews,但它们似乎没有涵盖这个问题。任何帮助将不胜感激。

In the app I am working on, I have action sheets and alert views which I would like dismissed when app enters the inactive/ background state.

I am using the UIApplicationWillResignActiveNotification instead of the UIApplicationDidEnterBackgroundNotification as I want the code to be compatible with iOS3.2.

-(void)applicationWillResignActive:(Notification *)notification{
    if (self.actionSheet && self.actionSheet.visible){
        NSLog(@" actionSheet is Visible");
        [self.actionSheet dismissWithClickedButtonIndex:0 animated:NO];
    }
}

Testing this in simulator (iphone 3.2, iOS4), with the actionSheet visible, I press the home button, but I do not get the "actionSheet is Visible" message. Yet when I re-open the app and dismiss it again with home button, I get the "actionSheet is Visible" message.

This suggests that the first time the actionSheet's visible property is not being set. Could there be a delay in the property being set? In fact I put a message in the method that displays the actionSheet

[self.actionSheet showInView:self.parentViewController.tabBarController.view];
if (self.actionSheet.Visible) NsLog(@" action Sheet visible");

even here I do not get the message. Where/ when is the visible property set? Am I doing something fundamentally wrong in trying to dismiss the actionSheet? I have seen similar very good and detailed solutions on dismissing alertViews in SO.... but they don't seem to cover this issue. Any help will be much appreciated.

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

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

发布评论

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

评论(1

一口甜 2024-09-21 15:24:20

为什么你甚至需要检查它是否可见?事实上,为什么你甚至需要检查它是否为零?您可以只输入 [self.actionSheet dismissWithClickedButtonIndex:0animated:NO]; ,它应该可以正常工作,就好像操作表存在一样,您将忽略它,如果不存在,您将只会调用 nil 上的方法,它什么也不做。

Why would you even need to check if it's visible? In fact, why would you even need to check it against nil? You could just put [self.actionSheet dismissWithClickedButtonIndex:0 animated:NO];, and it should work fine, as if the action sheet exists you will dismiss it, and if it doesn't, you will will just call the method on nil, which does nothing.

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