简体   繁体   English

关闭UIViewController而不关闭顶部的警报

[英]Dismiss a UIViewController without dismissing an alert on top of it

I have a UIViewController that presents a UIAlertController. 我有一个呈现UIAlertController的UIViewController。 I would like the UIAlertController to dismiss itself while still allowing the UIAlertController to stay on top. 我希望UIAlertController自行关闭,同时仍允许UIAlertController保持在最前面。

Here's the code to dismiss: 这是要关闭的代码:

[self dismissViewControllerAnimated:YES completion:nil];

I'll omit the code for UIAlertController, but I'm using this code to present: 我将省略UIAlertController的代码,但是我正在使用此代码来呈现:

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

I'm looking for a solution that can be contained within my single UIViewController subclass. 我正在寻找可以包含在单个UIViewController子类中的解决方案。

I suppose your scenario is like this: 我想你的情况是这样的:
A_ViewController pushed B_ViewController, B_ViewController presented alertController at some circumstances. A_ViewController推送了B_ViewController,B_ViewController在某些情况下提供了alertController。 Now you're at B_ViewController and want to dismiss itself without the alert disappear,right? 现在您在B_ViewController上,并且想要在警报不消失的情况下自行关闭,对吗? If I got this right,I don't think this gonna work. 如果我做对了,我认为这不会起作用。 Because alert depends on B_ViewController, if B is gone, so did alert. 因为警报取决于B_ViewController,所以如果B消失了,警报也是如此。
Here is my thought: 这是我的想法:
A_ViewController pushed B_ViewController, now we're at B, at some circumstances there should be an alert being presented,instead of letting B present the alert, we could let A present the alert(We could use delegate method to tell A to present an alert). A_ViewController推送了B_ViewController,现在我们在B处,在某些情况下应该显示一个警报,而不是让B呈现警报,我们可以让A呈现警报(我们可以使用委托方法告诉A呈现警报)。 And now, B and alert are independent,B gone,alert stays. 而现在,B和警报是独立的,B消失了,警报保持。 I hope this would help. 我希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM