2010-07-08 49 views
0

我正在运行需要启用LocationServices的应用程序。我正在检查他们是否通过拨打服务电话并发现错误。在错误情况下,我想弹出一个alertview,通知用户激活位置服务。当这个测试发生时,我已经打开了另一个AlertView。我想关闭那个,并给用户我之前提到的对话框。关闭UIAlertView并用另一个替换

目前,我有

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输出在那里,所以我知道它到了这种情况。

回答

1

这里您指定了委托:self,然后它搜索在UIAlertViewDelegate声明的警报处理程序,以及何时它没有发现它崩溃。

所以,你应该定义

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
在你的类

你也可以实现UIAlertViewDelegate的其他方法,它可以帮助你完成所需的任务。

+0

谢谢。我也注意到了。我在里面放了一些处理代码,现在它工作的很好。 – Adam 2010-07-09 21:07:31

0

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