2014-09-24 70 views
0

在我的應用程序中使用iOS 7.1中的UIAlertView顯示一些警報,在iOS 8中完美地顯示警報,但沒有按鈕取消,OK和其他...這會導致用戶無法關閉警報,並因此被卡在屏幕上,不得不關閉應用程序。iOS 8 UIAlertView不顯示按鈕

我試圖實現UIAlertView中和以前的版本爲iOS UIAlertController 8,看下面的代碼:

if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) { 
      UIAlertView *alerta = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"s000xS2", @"Alerta") message:NSLocalizedString(@"s000xS40", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"s000xS34", @"Não") otherButtonTitles:NSLocalizedString(@"s000xS35", @"Sim"), nil]; 

      [alerta show]; 
     }else{ 
      UIAlertController * alert= [UIAlertController 
              alertControllerWithTitle:NSLocalizedString(@"s000xS2", @"Alerta") 
              message:NSLocalizedString(@"s000xS40", nil) 
              preferredStyle:UIAlertControllerStyleAlert]; 

      UIAlertAction* sim = [UIAlertAction 
           actionWithTitle:NSLocalizedString(@"s000xS35", @"Sim") 
           style:UIAlertActionStyleDefault 
           handler:^(UIAlertAction * action) 
           { 
            [Util abrirSite:[[[Player sharedPlayer] emissora] site]]; 
            [alert dismissViewControllerAnimated:YES completion:nil]; 

           }]; 
      UIAlertAction* nao = [UIAlertAction 
            actionWithTitle:NSLocalizedString(@"s000xS34", @"Não") 
            style:UIAlertActionStyleDefault 
            handler:^(UIAlertAction * action) 
            { 
             [alert dismissViewControllerAnimated:YES completion:nil]; 

            }]; 

      [alert addAction:sim]; 
      [alert addAction:nao]; 


      [self presentViewController:alert animated:NO completion:nil]; 
     } 

有了這個代碼,我有同樣的問題,該按鈕不會顯示在警報顯示,有什麼建議解決這個問題?

請注意,我正在使用字符串進行國際化,他們通常都是工作的,已經通過直接放置字符串(@「...」)進行測試,但沒有奏效。

回答

1

試試這個:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"ALERTA!" message:@"What will you do?" **preferredStyle:UIAlertControllerStyleAlert**]; 
__weak ViewController *wself = self; 

UIAlertAction *nao = [UIAlertAction actionWithTitle:@"I'm doing something" ***style:UIAlertActionStyleCancel*** handler:^(UIAlertAction *action) { 
    __strong ViewController *sself = wself; 
    sself.**lbl**.text = @"You did something!"; **//the text "You did something!" gets displayed on a label(if created) named lbl** 
}]; 
[alert addAction:nao]; 
[self presentViewController:alert animated:NO completion:nil];