[英]How can I check and determine which view controller in storyboard is currently showing?
If the application was previously in the background, when applicationDidBecomeActive
is called,how can I optionally refresh the user interface ? 如果应用程序以前在后台,则在调用
applicationDidBecomeActive
时,如何选择刷新用户界面?
I expect the current view controller is always the initial view controller in storyboard.I can't get the pointer to storyboard in my main AppDelegate.m
. 我希望当前的视图控制器始终是情节提要中的初始视图控制器。我无法在主
AppDelegate.m
获得指向情节AppDelegate.m
的指针。
How can I check and determine which view controller is currently showing ? 如何检查并确定当前正在显示哪个视图控制器?
If you just want a pointer to your storyboard then you can do this: 如果您只想要指向情节提要的指针,则可以执行以下操作:
UIStoryboard *sb = [[[self window] rootViewController] storyboard];
where rootViewController
is actually the initial view controller of your storyboard. 其中
rootViewController
实际上是情节rootViewController
的初始视图控制器。 If you expect this controller to be the current controller (as you say) then you're good to go, but if you want to actually update your UI, then I guess you could post a custom notification from the delegate (inside applicationDidBecomeActive
), and register each controller that may be interested to catch it so it can update its UI (or just add self
as observer for UIApplicationDidBecomeActiveNotification
to catch the same one that your delegate catches...). 如果您希望此控制器是当前的控制器(如您所说),那么您就可以了,但是如果您想实际更新UI,那么我想您可以在委托中发布自定义通知(在
applicationDidBecomeActive
内部),并注册每个可能有兴趣捕获它的控制器,以便它可以更新其UI(或只是将self
添加为UIApplicationDidBecomeActiveNotification
观察者以捕获您的委托捕获的相同控制器...)。
PS. PS。 If your
rootViewController
is a UINavigationController
you can get the currently showing controller like this: 如果您的
rootViewController
是UINavigationController
,则可以获取当前显示的控制器,如下所示:
id currentController = [[[self window] rootViewController] visibleViewController];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.