Iphone 检测单击了哪个UIAlertView

Iphone 检测单击了哪个UIAlertView,iphone,objective-c,cocoa-touch,uialertview,Iphone,Objective C,Cocoa Touch,Uialertview,我需要在我的应用程序加载时弹出警报。。。我称之为“完成发射”。。 单击“确定”按钮后,需要显示另一条警报消息我使用ClickedButtonIndex 现在,当我点击ok按钮时,它会一次又一次地呼叫。。alertview 我只需要打一次电话。。。怎么办 -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // O

我需要在我的应用程序加载时弹出警报。。。我称之为“完成发射”。。 单击“确定”按钮后,需要显示另一条警报消息我使用ClickedButtonIndex

现在,当我点击ok按钮时,它会一次又一次地呼叫。。alertview

我只需要打一次电话。。。怎么办

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    // Add the tab bar controller's view to the window and display.
    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];
    viewControllersList = [[NSMutableArray alloc] init];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Alow this app to use your GPS location"
    delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
    [alert show];
    [alert release];

}

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


    if (buttonIndex==0) {
        NSLog(@"NO");
    }
    else    {

        NSLog(@"Yes");
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Do you want's to receive Push messages."
        delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
        [alert show];
        [alert release];
    }

}

@提前感谢。

在第二个警报视图中设置
代理:nil

我是说


定义每个UIAlertView,并在代理中查找要响应的警报:

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

    if(alert1) {
        if (buttonIndex==0) { 

            NSLog(@"NO"); 
        } else {

            NSLog(@"Yes");
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Do you want's to receive Push messages." delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
            [alert show];
            [alert release];
        }
    } else {

        /*  the second alertview  using the same buttonIndex  */
    }

}

如果您想要接收位置,只需请求它,系统将自动为您显示消息。请遵循以下示例:

- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:tabBarController.view];
// Create a location manager instance to determine if location services are enabled. This manager instance will be
// immediately released afterwards.
CLLocationManager *manager = [[CLLocationManager alloc] init];
if (manager.locationServicesEnabled == NO) {
    UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:@"Location Services Disabled" message:@"You currently have all location services for this device disabled. If you proceed, you will be asked to confirm whether location services should be reenabled." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [servicesDisabledAlert show];
    [servicesDisabledAlert release];
}
[manager release];                                  
}


推送通知也是如此。

虽然您已经有了许多实现解决方案……但我认为更好的做法是为每个AlertView分配一个标记,并在检测按钮点击之前检查调用AlertView的标记。希望这能有所帮助。
@杰拉德:虽然位置管理器和推送通知服务都会产生系统生成的消息,但用户可以检查这些消息,不再显示。所以更好的高投诉方法是应用程序在需要推送或位置管理器时生成消息

您还可以向AlertView中添加一个标记,稍后在ClickedButtonIndex方法中检查该标记

        UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"" message:@"All local datawill be erased. Erase local data?" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Erase", @"Cancel",nil];
        alert.tag =123; // added the tag so we can prevent other message boxes ok button to mix up 
        [alert show];
然后


在第二个警报中设置委托:nil始终欢迎……。如果答案对您有效,请接受它。@Kiran这是您为两个警报按钮代码编码时的方式(如果您需要在单击第二个警报时执行任何操作)。
        UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"" message:@"All local datawill be erased. Erase local data?" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Erase", @"Cancel",nil];
        alert.tag =123; // added the tag so we can prevent other message boxes ok button to mix up 
        [alert show];
    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex ==0 && alertView.tag==123){
       // Do what ever you wish
    }
}