需要在所有 UIAlertControllers 被解雇后采取行动

Need action to happen after all UIAlertControllers dismissed

我需要我的应用程序中的每个 UIAlertController 在用户按下按钮时(即当它被关闭时)执行特定操作。截至目前,我能想到的唯一方法是将此操作单独编码到每个按钮处理程序中,如下所示:

UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action)
{
    [self doSomeAction];
}];

UIAlertController 没有代表。我如何才能在每次解除警报时完成相同的操作,而不必一遍又一遍地重复相同的代码?

最简单的解决方案是 subclass UIAlertController。然后覆盖 viewDidDisappear。为那里的每个警报添加您想要发生的任何 "one specific thing"。现在,只要您希望完成此自定义行为,就可以使用您的自定义警报控制器 class。