关闭 UIAlertView 并替换为另一个

发布于 2024-09-08 13:59:00 字数 739 浏览 6 评论 0原文

我正在运行一个需要启用 LocationServices 的应用程序。我正在通过调用服务并捕获错误来检查它们是否存在。在错误情况下,我想弹出一个警报视图,通知用户激活位置服务。当这个测试发生时,我已经打开了另一个 AlertView。我想关闭该对话框并向用户提供我之前提到的对话框。

目前,我有

case kCLErrorDenied: // CL access has been denied (eg, user declined location use)

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"NOTICE" 
               message:@"Sorry, this application needs your location.  Please select 'Allow' when asked to use your current location.  You don't need to be on or near the trail."
                 delegate:self
              cancelButtonTitle:nil 
              otherButtonTitles:@"EXIT"];
   [alert show];
   [alert release];
   //exit(0);
   break;

这导致应用程序退出。我在那里有一个 NSLog 输出,所以我知道它适用于这种情况。

I'm running an application that requires LocationServices be enabled. I'm checking if they are by making a call to the service and catching the error. In the error case, I want to pop up an alertview notifying the user to activate location services. I have another AlertView open already when this test happens. I want to close that one and give the user the dialog box I mentioned previously.

Currently, I have

case kCLErrorDenied: // CL access has been denied (eg, user declined location use)

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"NOTICE" 
               message:@"Sorry, this application needs your location.  Please select 'Allow' when asked to use your current location.  You don't need to be on or near the trail."
                 delegate:self
              cancelButtonTitle:nil 
              otherButtonTitles:@"EXIT"];
   [alert show];
   [alert release];
   //exit(0);
   break;

This causes the app to just exit. I had an NSLog output in there so I know it gets to this case.

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

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

发布评论

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

评论(2

最佳男配角 2024-09-15 13:59:00

在这里,您指定 delegate:self,然后它会搜索在 UIAlertViewDelegate 中声明的警报处理程序,如果找不到,则会崩溃。

所以你应该

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

在你的班级中定义。

您还可以实现 UIAlertViewDelegate 的其他方法,这将帮助您完成所需的任务。

here you are specifying delegate:self, then it searches for alert handlers declared at UIAlertViewDelegate and when it doesn't find it crashes.

So you should define

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

in your class.

Also you can implement other methods of UIAlertViewDelegate which will help you in your required task.

轻许诺言 2024-09-15 13:59:00

您需要使用实例变量跟踪上一个警报,并在显示新对话框之前调用该方法来关闭上一个对话框。您还需要一个警报的委托处理程序。

You need to keep track of the previous alert with an instance variable, and call the method to dismiss that previous dialog before showing the new one. You also need a delegate handler for the alert.

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