ios - Alertview Void Alert3 clickedButtonAtIndex 未被调用

标签 ios uibutton uialertview

我目前正在编写一个应用程序,它有一个 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 方法,但没有任何效果。

谢谢

最佳答案

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

你必须使用:

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

代替:

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

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

关于ios - Alertview Void Alert3 clickedButtonAtIndex 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29732936/

相关文章:

iphone - iOS 同步动画

ios - Swift ios 推送通知通知在应用程序打开时不工作,但在应用程序关闭时工作

ios - Swift - 如何访问设备上的所有 pdf 文件

iphone - 如何在操作中找到正确的 UIButton 对象

ios - 以编程方式将 UIButton 添加到 rootview,我做错了什么?

ios - iOS 中的自定义切换

iphone - 我想在 UIAlertView 上显示 UIProgressView

ios - localNotification/uiTableView/删除行 -> 错误 "invalid number of rows"

iphone - 管理以单一方式触发的多个本地通知的警报?

ios - 如果推送多个 AlertView,Swift 仅显示一个 AlertView