关闭 UIAlertView 并替换为另一个
我正在运行一个需要启用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这里,您指定 delegate:self,然后它会搜索在 UIAlertViewDelegate 中声明的警报处理程序,如果找不到,则会崩溃。
所以你应该
在你的班级中定义。
您还可以实现 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
in your class.
Also you can implement other methods of UIAlertViewDelegate which will help you in your required task.
您需要使用实例变量跟踪上一个警报,并在显示新对话框之前调用该方法来关闭上一个对话框。您还需要一个警报的委托处理程序。
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.