排序2个UIalertview按钮点击

时间:2011-08-25 01:27:59

标签: iphone objective-c uialertview

我在同一页面上有2个提醒。问题是clickedButtonAtIndex正在回答两个警报而不仅仅是第二个警报。我该如何分开它们?

UIAlertView *passwordAlert = [[UIAlertView alloc] initWithTitle:@"Phone Number" message:@"\n\n\n"
                                                       delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"OK",nil), nil];

UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Warning" message:@"Please Enter correct phone no." delegate:self cancelButtonTitle:nil otherButtonTitles:@"Try Again", nil];

- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {

在第一个上输入一个电话号码并点击确定。如果它有效,那很好。但是,如果没有第二个警报显示。现在当他们击中"再试一次" clickedButtonAtIndex在第一个和第二个警报上运行。我需要它只在第二个运行。

2 个答案:

答案 0 :(得分:0)

尝试为每个UIAlertView添加一个标记,然后在alertView:clieckedButtonAtIndex中使用该标记来确定哪个UIAlertView处于活动状态。

请参阅上一个问题的详细信息和示例代码:Several UIAlertViews for a delegate

答案 1 :(得分:0)

您需要做的是为警报视图提供不同的标记,然后通过标记访问: -

UIAlertView *passwordAlert = [[UIAlertView alloc] initWithTitle:@"Phone Number" message:@"\n\n\n"
                                                       delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"OK",nil), nil];
passwordAlert.tag=1;

UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Warning" message:@"Please Enter correct phone no." delegate:self cancelButtonTitle:nil otherButtonTitles:@"Try Again", nil];
alert.tag=2;

- (void)alertView:(UIAlertView *)alert didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(alert.tag==1)
    {
        if (buttonIndex==0) {

        }
        else if (buttonIndex==1) {

        }
         }
if(alert.tag==2)
    {
        if (buttonIndex==0) {

        }
        else if (buttonIndex==1) {

        }
}