【问题标题】:Alertview Void Alert3 clickedButtonAtIndex is not calledAlertview Void Alert3 clickedButtonAtIndex 未被调用
【发布时间】:2015-04-19 16:58:32
【问题描述】:

我目前编写了一个应用程序,它有一个 uibutton,允许用户在数据库中发送评论。

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

我也使用以下方法: - (void)myAlert3:(UIAlertView *)myAlert3 didDismissWithButtonIndex: (NSInteger)buttonIndex

但是当我调用它时,我没有反应,也没有日志。 我读了几篇 stackoverflow 的文章,但没有一篇适合我。

这是我的代码:

-(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 方法,但没有任何效果。

谢谢

【问题讨论】:

    标签: ios uibutton uialertview


    【解决方案1】:

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

    你必须使用:

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

    代替:

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

    您可以更改参数名称,但如果您更改委托方法的名称,代码将不起作用。

    【讨论】:

    • 非常感谢:D
    猜你喜欢
    • 2011-01-27
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-31
    • 1970-01-01
    • 2020-04-26
    • 1970-01-01
    相关资源
    最近更新 更多