2015-01-06 4 views
1

У меня есть два UIAlertview, я хочу перейти на другую страницу, когда я нажимаю внутри, я создаю два xib-файла и импортирую их в главный Viewcontroller, но не знаю, почему это невозможно показать, это ничего неправильный флаг, когда я проверить ~ Вот мой код:Два UIAlertView

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

еще не решил еще ~ –

ответ

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]; чтобы показать ваше предупреждение

+0

спасибо, он решает мою проблему ~ –