0

在我的应用程序中使用 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];
        }

使用此代码我有同样的问题,按钮未显示在警报中,有什么建议可以解决这个问题吗?

请注意,我使用字符串进行国际化,它们通常可以工作,已经通过直接放置字符串(@“...”)进行了测试,但它不起作用。

4

1 回答 1

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];
于 2014-10-23T06:20:59.077 回答