尝试出现已经呈现的* on *(null)

时间:2016-12-07 10:57:20

标签: objective-c uialertcontroller

我使用以下代码来显示警报控制器,但有时它会发出上述消息并且警报控制器停止响应。它是什么意思以及如何修复它?

+(void)showAlertFor:(UIViewController *)viewController Title:(NSString*)title WithMessage:(NSString *)message
{

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error" message:message   preferredStyle:UIAlertControllerStyleAlert]; //Getting the alert view controller
    UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

    }];

    [alertController addAction:ok];

    [viewController  presentViewController:alertController animated:YES completion:nil];
}

1 个答案:

答案 0 :(得分:0)

试试这个

+(void)showAlertFor:(UIViewController *)viewController withTitle:(NSString*)title withMessage:(NSString *)message {

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error" message:message   preferredStyle:UIAlertControllerStyleAlert]; //Getting the alert view controller
    UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

    }];

    [alertController addAction:ok];
    dispatch_async(dispatch_get_main_queue(), ^ {
    [viewController  presentViewController:alertController animated:YES completion:nil];
    });
}

在主线程上调用它将解决您的问题。并确保您没有同时展示任何其他控制器。