2012-07-10 17 views
7

Jestem nowy w iPhone DeveloperUIAlertView Kliknij wydarzenie wewnątrz UIAlertView delegata

chcę wdrożyć 2 powiadomienie widok jeden po drugim, jak wtedy, gdy użytkownik naciśnie przycisk usuwania, 1. Widok alert poprosi Are you sure want to Delete ? z dwoma przyciskami yes i no

teraz, gdy użytkownik naciśnie yes, następnie 2-sze widok alert będzie pochodzić z komunikatem Deleted Successfully ! ten alert widok zawiera tylko OK przycisk, teraz na kliknięcie tego przycisku OK chcę zadzwonić jedną metodę.

i jeśli użytkownik naciśnie No, nic nie powinno się wydarzyć, a alert powinien zostać odrzucony.

Tu jest mój urywek kodu,

-(void)DeletebtnCliked:(id)sender 
{ 
    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Are you sure want to delete ?" 
                 message:nil delegate:self 
               cancelButtonTitle:nil 
               otherButtonTitles:@"Yes",@"No",nil]; 
    [alertView show]; 
    [alertView release]; 
} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == 0) 
    {    
     UIAlertView* alertew = [[UIAlertView alloc] initWithTitle:@"Deleted Successfully !" 
                  message:nil delegate:self 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]; 
     [alertew show]; 
     [alertew release]; 

     if (buttonIndex == 0) 
     { 
      [self MethodCall]; 
     } 
    } 
    else if (buttonIndex == 1) 
    { 
     [alertView dismissWithClickedButtonIndex:1 animated:TRUE]; 
    } 
} 

po napisaniu tego kodu jestem w srodku nieskończonej pętli.

Każda pomoc zostanie doceniona.

+0

W razie wypadku: 'if (buttonIndex == 0)', czemu sprawdzając tym samym stanie, w środku? –

+0

'jeśli (buttonIndex == 0)' jest, gdy użytkownik naciśnie przycisk 'Tak' – Krunal

Odpowiedz

11
alertView.tag = 1; 
alertew.tag = 2; 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (alertView.tag == 2) 
    { 
     //Do something 
    } 
    else 
    { 
     //Do something else 
    } 
} 
4

Ustaw delegata drugiego wpisu widoku danych, by nil:

UIAlertView* alertew = [[UIAlertView alloc] initWithTitle:@"Deleted Successfully !" 
                  message:nil delegate:nil 
                cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
1

użyć znaczników do opanowania sytuacji jak po lub po prostu ustawić zero Delegat wewnętrznej alertView który jest wewnątrz Methode delegata tak że nigdy nie zadzwoni.

-(void)DeletebtnCliked:(id)sender 
{ 
    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Are you sure want to delete ?" 
                message:nil delegate:self 
              cancelButtonTitle:nil 
              otherButtonTitles:@"Yes",@"No",nil]; 
alertView.tag = 1; 
[alertView show]; 
[alertView release]; 
} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
if (buttonIndex == 0 && alertView.tag == 1) 
{    
    UIAlertView* innerAlert = [[UIAlertView alloc] initWithTitle:@"Deleted Successfully !" 
                 message:nil delegate:nil 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil]; 
    innerAlert.tag = 2; 
    [innerAlert show]; 
    [innerAlert release]; 

    if (buttonIndex == 0 && alertView.tag == 1) 
    { 
     [self MethodCall]; 
    } 
} 
else if (buttonIndex == 1 && alertView.tag == 1) 
{ 
    [alertView dismissWithClickedButtonIndex:1 animated:TRUE]; 
} 
} 
0

spróbuj tego: -

-(void)button:(UIButton *)buttonDelete{ 
      UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"delete" message:@"Do you Want to delete" delegate:self cancelButtonTitle:@"Cancle" otherButtonTitles:@"Yes", nil]; 
      alertView.delegate = self; 
      alertView.tag = 2000; 
      [alertView show]; 
     } 
-(void)buttonUpdate:(UIButton *)buttonEdit{ 

     UIAlertView *alertView2 = [[UIAlertView alloc] initWithTitle:@"Update" message:@"Do you Want to Update" delegate:self cancelButtonTitle:@"Cancle" otherButtonTitles:@"Yes", nil]; 
      alertView2.delegate = self; 
      alertView2.tag = 20001; 
      [alertView show]; 
    } 
-(void)buttonAdd:(UIButton *)buttonAdd{ 
     UIAlertView *alertView3 = [[UIAlertView alloc] initWithTitle:@"Add" message:@"Do you Want to Add" delegate:self cancelButtonTitle:@"Cancle" otherButtonTitles:@"Yes", nil]; 
      alertView3.delegate = self; 
      alertView3.tag = 20002; 
      [alertView show]; 
    }  
    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
      if (alertView.tag == 2000){ 
       if (buttonIndex==0) { 
        NSLog(@"Delete Cancel Button click"); 
       } 
       else{ 
        NSLog(@"Delete yes Button is click"); 
       } 

      } 
      if (alertView.tag == 20001){ 
       if (buttonIndex==0) { 
        NSLog(@"update Cancel Button click"); 
       } 
       else{ 
        NSLog(@"update yes Button is click"); 
       } 

      } 
      if (alertView.tag == 20002){ 
       if (buttonIndex==0) { 
        NSLog(@"Add Cancel Button click"); 
       } 
       else{ 
        NSLog(@"Add yes Button is click"); 
       } 

      } 
     }