ios - 不要关闭 UIAlertController

标签 ios objective-c uialertview uialertcontroller

我目前有一个 UIAlertController,我需要将其设置为不可关闭。按下操作按钮时不应关闭警报。

我该怎么做?

 UIAlertController *alert;

    int bestScore = [[[NSUserDefaults standardUserDefaults] objectForKey:@"bestScore"] intValue];
    if (!bestScore || bestScore < _score){
        [[NSUserDefaults standardUserDefaults] setObject:@(_score) forKey:@"bestScore"];
        alert = [UIAlertController alertControllerWithTitle:@"GAME OVER "
                                                    message:[NSString stringWithFormat:@"NEW RECORD! \n SCORE : %d  \n\n\n\n\n\n", _score] preferredStyle:UIAlertControllerStyleActionSheet];
    }
    else   alert = [UIAlertController alertControllerWithTitle:@"GAME OVER"
                                                       message:[NSString stringWithFormat:@"SCORE : %d \n Best score : %d  \n\n\n\n\n\n ", _score, bestScore] preferredStyle:UIAlertControllerStyleAlert];

    [alert addAction:[UIAlertAction actionWithTitle:@"Try again" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        [self newGame];
        [self addNewView];

    }]];


      [alert addAction:[UIAlertAction actionWithTitle:@"Answer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                [alert viewWillDisappear:NO];

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

最佳答案

我建议创建一个包含 UIView 的 UIViewController。在此 UIView 中,您将能够显示所需信息并添加所需的自定义按钮操作。

为了让 UIView 看起来像模态视图 Controller ,添加一个带有 UIBlurEffectStyle 的 UIVisualEffectView。

这就像使用 Storyboard/xib 创建传统 View Controller 一样简单,在界面构建器中添加所需的 UIView,然后链接关联的 View Controller 类。完成初始设置和用户界面后,将以下代码添加到 viewDidLoad。此外,您可以在 viewWillAppear 和 viewWillDisappear 中执行所需的动画等。

UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]
UIVisualEffectsView *blurView = [[UIVisualEffectView alloc] initWithEffect:effect];
[self.view insertSubview:blurView atIndex:0];

关于ios - 不要关闭 UIAlertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41208520/

相关文章:

iphone - 如何将变量传递给 UIAlertView 委托(delegate)?

iphone - iOS 发布到 Facebook 应用墙

ios - 如何在 quickblox iOS 中将视频文件作为附件发送?

ios - xCode、iOS、cocoa——实现带登录页面的应用

ios - 如何在没有按钮的情况下关闭 UIAlertController

IOS UIAlertView 未显示

ios - 枚举对象并将其添加到 NSMutableSet 时的 exc_bad_access

iphone - Storyboard和 View 转换

objective-c - 来自 UICollectionView 的按钮的索引路径

iphone - 有什么方法可以知道 iPhone 连接到哪个网络(LTE 与 GSM)