两个 UIAlertView

Two UIAlertView

我有两个 UIAlertview ,我想在点击里面时转到不同的页面,我创建了两个 xib 文件,并将它们导入到主 Viewcontroller 中,但不知道为什么不能显示它,这没什么查错flag~ 这是我的代码:

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

    }
}

请帮忙谢谢~

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];显示您的警报