iOS - 如何检查模式视图是否存在
有没有办法检查模式视图是否存在?我想仅在存在模式视图时运行方法。另外,如果我有多个模态视图,有没有办法检查是否存在某个模态视图。
我使用以下代码来呈现和关闭模态视图:
[self presentModalViewController:myModalView animated:YES];
[self dismissModalViewControllerAnimated:YES];
提前谢谢您!
干杯, 埃文
PS.我的模态视图有一个视图控制器,但我想检查模态视图是否存在于异步运行的单独类中。
Is there a way to check if a modal view is present? I'd like to run a method only if a modal view is present. Also, if I have multiple modal views, is there a way to check if a certain modal view is present.
I use the following code to present and dismiss modal views:
[self presentModalViewController:myModalView animated:YES];
[self dismissModalViewControllerAnimated:YES];
Thank you in advance!
Cheers,
Evan
PS. My modal view has a view controller, but I'd like to check if the modal view is present from a separate class that is running asynchronously.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否从父视图控制器检查模式视图控制器是否存在?如果是这样,您只需检查该视图控制器的 modalViewController 属性:
如果您想检查特定的模态视图控制器,您可以获取模态视图控制器的类名,如下所示:
Are you checking the presence of a modal view controller from the parent view controller? If so, you can just check that view controller's modalViewController property:
If you want to check for a particular modal view controller, you can get the modal view controller's class name like this:
您可以使用以下方法进行检查:
self.presentedViewController
,它返回此视图控制器呈现的视图控制器,或其在视图控制器层次结构中的祖先之一。
You can check using:
self.presentedViewController
, which returnsThe view controller that is presented by this view controller, or one of its ancestors in the view controller hierarchy.
对我有用的是:
据我测试,这适用于 iOS7 和 iOS8。不过iOS6没试过。
What worked for me is following:
As far as I tested it, this works for iOS7 and iOS8. Didn't try on iOS6 however.
您可以从父
视图控制器
检查模态视图控制器
是否存在You can check the presence of a modal
view controller
from the parentview controller