iOS 8 UIAlertView没有显示按钮

时间:2014-09-24 23:58:36

标签: ios8 uialertview uialertcontroller

使用iOS 7.1中的UIAlertView在我的应用程序中显示一些警报,在iOS 8中完美地运行警报,但没有按钮取消,OK和其他...这导致用户无法关闭警报并因此获得卡在这个屏幕上,不得不关闭应用程序。

我尝试为iOS UIAlertController 8实现UIAlertView和以前的版本,请参阅下面的代码:

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 个答案:

答案 0 :(得分: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];