两个UIAlertView

时间:2015-01-06 02:42:10

标签: xcode6 uialertview

我有两个UIAlertview,我想在我点击里面的时候去不同的页面,我创建两个xib文件,并在主Viewcontroller中导入它们,但不知道为什么不能显示它,那是没有错的标志当我检查〜 这是我的代码:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"LP01;" message:@"No Connection" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Help", nil];


UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"LP01;" message:@"No Connection" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Help", nil];




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


            if (buttonIndex == 1) {

        AViewController *switch1 = [[AViewController alloc]
                                   initWithNibName:nil bundle:nil];
        [self presentViewController:switch1 animated:YES completion:NULL];

            }
}

- (void)alert1:(UIAlertView *)alertview clickedButtonAtIndex:(NSInteger)buttonIndex {



    if (buttonIndex == 1) {


        BViewController *switch2 = [[BViewController alloc]
                                    initWithNibName:nil bundle:nil];
        [self presentViewController:switch2 animated:YES completion:NULL];

    }
}

请帮助和谢谢〜

1 个答案:

答案 0 :(得分:0)

UIAlertView *firstAlert = [[UIAlertView alloc] initWithTitle:@"LP01;" message:@"No Connection" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Help", nil];


UIAlertView *secondAlert = [[UIAlertView alloc] initWithTitle:@"LP01;" message:@"No Connection" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Help", nil];

//记住委托方法对于与之相关的任何数量的元素都是相同的。因此,无论您有2个还是3个或5个UIAlertView,您的委托方法都只会写一次。

- (void)alert:(UIAlertView *)alertview clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(alertview == firstAlert){



            AViewController *switch1 = [[AViewController alloc]
                                        initWithNibName:nil bundle:nil];
            [self presentViewController:switch1 animated:YES completion:NULL];


    }
    else if(alertview == secondAlert){



            BViewController *switch2 = [[BViewController alloc]
                                        initWithNibName:nil bundle:nil];
            [self presentViewController:switch2 animated:YES completion:NULL];


    }
}

//不要忘记给[firstAlert show]打电话;或[secondAlert show];显示提醒