2010-12-16 29 views
0

je dois apparaître alerte quand mon application chargée ... Je l'ai appelé didfinished lancement .. après avoir cliqué sur le bouton ok besoin pour afficher un autre message d'alerte-je utiliser clickedButtonAtIndex ...qui UIAlertView a été Detecting cliqué

maintenant quand j'ai cliqué sur le bouton ok son appel encore et encore .. le alertview ..

Je dois appeler une seule fois ... que faire?

-(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]; 
    } 

} 

@thanks à l'avance.

+2

délégué ensemble: néant en deuxième alertView – Saawan

+0

@ merci ranjeet.sajwan –

+0

k accueillir toujours ........ – Saawan

Répondre

3

Définir chaque UIAlertView et dans le regard délégué pour lequel Alerte à répondre à:

-(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 */ 
    } 

} 
+0

@Kiran C'est ainsi que vous codez le code des deux boutons d'alerte (au cas où vous auriez besoin d'effectuer une action sur un clic de seconde alerte). – Ishu

4

mis delegate:nil deuxième alertView
Je veux dire

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

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

+1 pour attraper la bonne chose au bon endroit. – Ishu

1

Si ce que vous voulez est de recevoir la emplacement, il suffit de le demander et le système affichera automatiquement le message pour vous. Suivez cet exemple:

- (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];         

}

http://developer.apple.com/library/ios/#samplecode/LocateMe/Listings/Classes_AppDelegate_m.html%23//apple_ref/doc/uid/DTS40007801-Classes_AppDelegate_m-DontLinkElementID_4

Même pour les notifications push.

0

bien que vous ayez déjà de nombreuses solutions d'implémentation ... mais je pense que la meilleure pratique serait d'assigner un tag à chacun de vos AlertView et avant de détecter le bouton tapé vérifier le tag d'invocation AlertView.Hope cela aide. @Gerard: Bien que le gestionnaire de localisation et le service de notification push soulèvent les messages générés par le système, ceux-ci peuvent être cochés par les utilisateurs.

3

Vous pouvez également ajouter un tag à votre AlertView et te vérifier l'étiquette plus tard la méthode clickedButtonAtIndex

 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]; 

puis

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    if (buttonIndex ==0 && alertView.tag==123){ 
     // Do what ever you wish 
    } 
} 
Questions connexes