2010-12-16 4 views
0

мне нужно выскакивать уведомление, когда мое приложение загружается ... Я назвал это didfinished запуск .. после нажатия кнопки ОК необходимо, чтобы показать другой предупредительное сообщение я использовать clickedButtonAtIndex ...обнаруживая который UIAlertView нажал

сейчас когда я нажал кнопку 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]; 
    } 

} 

@thanks заранее.

+2

набор делегата: ноль во втором alertView – Saawan 2010-12-16 04:35:34

+0

@ спасибо ranjeet.sajwan – 2010-12-16 04:36:44

+0

k добро пожаловать всегда ........ – Saawan 2010-12-16 04:38:18

ответ

3

Определить каждый 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 */ 
    } 

} 
4

набор delegate:nil во втором alertView
я имею в виду

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

Если то, что вы хотите получить местоположение, просто запросите его, и система автоматически отобразит сообщение для вас. Следуйте этому примеру:

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

Same для уведомления толчка.

0

хотя у вас уже много решений по внедрению ... но я думаю, что лучшей практикой было бы назначить тег для каждого из ваших AlertView и до обнаружения нажатия кнопки проверить метку вызова AlertView. Надеюсь, это поможет. @Gerard: Несмотря на то, что оба диспетчера местоположений и службы уведомлений с уведомлением поднимают сгенерированные системой сообщения, они могут быть отключены пользователями, которые не будут отображаться повторно. Поэтому лучше, метод HIG-жалобы является приложением, генерирующим приложению, когда требуются диспетчер push или location.

3

Вы также можете добавить тег в AlertView и тэ проверить тег позже метода 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]; 

затем

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    if (buttonIndex ==0 && alertView.tag==123){ 
     // Do what ever you wish 
    } 
} 
Смежные вопросы