Alertview Void Alert3 clickedButtonAtIndex 未被调用

Alertview Void Alert3 clickedButtonAtIndex is not called

我目前正在编写一个应用程序,它有一个允许用户在数据库中发送评论的 ui 按钮。

如果某些字段为空,我会在我的按钮中创建多个条件来显示一些 UialertView。

我也是用下面的方法: - (void)myAlert3:(UIAlertView *)myAlert3 didDismissWithButtonIndex: (NSInteger)buttonIndex

但是调用的时候没有任何反应,也没有日志。 我阅读了一些关于 Whosebug 的文章,但是 none 和我一起工作。

这是我的代码:

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


}
}

和方法:

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

}
}

我也尝试了 willDismissWithButtonIndex 和 clickedButtonAtIndex 方法,但没有任何效果。

谢谢

我认为您的错误在于 alertview 委托方法的名称。

您必须使用:

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

而不是:

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

您可以更改参数名称,但如果更改委托方法的名称,代码将无法运行。