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];
}
}
请帮助和谢谢〜
答案 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];显示提醒