2016-12-07 66 views
0

我正在使用以下代码来显示警报控制器,但有时它会收到上述消息并且警报控制器会停止响应。这是什么意思?固定?尝试在*上呈现*(已存在)(空)

+(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]; 
} 
+0

检查您是否提供多个控制器。 –

+0

这可以怎么做? – TestShroff

+0

@TestShroff你可以从同一个地方的两个地方调用'showAlertFor'吗?或者同时解雇VC? – PiyushRathi

回答

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]; 
    }); 
} 

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

+0

它现在给出以下警告,并仍然会导致问题“尝试加载视图控制器的视图时,它是释放是不允许的,并可能导致未定义的行为”。如何解决这个问题? – TestShroff

相关问题