f1rstsurf
f1rstsurf

Reputation: 647

Alertview Void Alert3 clickedButtonAtIndex is not called

i currently code an application which has an uibutton which allow users to send a comment in a database.

I created numerous conditions in my button to show some UialertView, if some fields are empty.

I also use the following method : - (void)myAlert3:(UIAlertView *)myAlert3 didDismissWithButtonIndex: (NSInteger)buttonIndex

but when i call it, i have no reaction and no log. I read few article of stackoverflow, but none work with me.

this is my code :

-(IBAction)addData:(id)sender{

///////////////////////////ALERTE SI LE PSEUDO/COMMENTAIRE EST VIDE////////////////////////////////////////////

if ((![_pseudo.text length]) || (![_pseudo.text length]))
{

    UIAlertView *myAlert1 = [[UIAlertView  alloc]initWithTitle:@"Alerte"message:@"Merci de renseigner le Pseudo" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles: nil];
    [myAlert1 show];
}

else if ((![_comment.text length]) || (![_comment.text length]))
{

    UIAlertView *myAlert2 = [[UIAlertView  alloc]initWithTitle:@"Alerte"message:@"Merci d'écrire votre commentaire" delegate:nil cancelButtonTitle:@"Okay " otherButtonTitles: nil];
    [myAlert2 show];

}
///////////////////////////FIN ALERTE SI LE PSEUDO/COMMENTAIRE EST VIDE////////////////////////////////////////////

///////////////SI PSEUDO EST SUPERIEUR A 3 ET COMMENTAIRE A 10 ON EXECUTE LA METHODE///////////////////////////////
else if (_pseudo.text.length > 3 && _comment.text.length > 10)
{



    //Message alerte pour confirmation envoie
    UIAlertView *myAlert3 = [[UIAlertView alloc] initWithTitle:@"Confirmation" message:@"En appuyant sur OUI vous acceptez de façon inconditionnelles les termes EULA d'Apple" delegate:self cancelButtonTitle:@"Non" otherButtonTitles:@"Oui", nil];
    [myAlert3 show];


}
}

and the method :

 - (void)myAlert3:(UIAlertView *)myAlert3 didDismissWithButtonIndex:(NSInteger)buttonIndex

{
if (buttonIndex == 0)

{     NSLog(@"button no");
    _pseudo.hidden=NO;
    _comment.hidden=NO;
}
if (buttonIndex == 1)
{
    NSLog(@"button yes");
    _pseudo.hidden=YES;
    _comment.hidden=YES;
    //_up.hidden=YES;

}
}

I also tried willDismissWithButtonIndex and clickedButtonAtIndex metho , but nothing work.

Thank's

Upvotes: 0

Views: 84

Answers (1)

Niccolò Passolunghi
Niccolò Passolunghi

Reputation: 6024

I think your mistake is on the alertview delegate method's name.

You had to use:

- (void)alertView:(UIAlertView *)myAlert3 didDismissWithButtonIndex:(NSInteger)buttonIndex

instead of:

- (void)myAlert3:(UIAlertView *)myAlert3 didDismissWithButtonIndex:(NSInteger)buttonIndex

You can change the parameters name but if you change the delegate method's name, the code won't work.

Upvotes: 3

Related Questions