简体   繁体   English

如何检查并确定情节提要中当前显示的视图控制器?

[英]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: 如果您的rootViewControllerUINavigationController ,则可以获取当前显示的控制器,如下所示:

id currentController = [[[self window] rootViewController] visibleViewController];

暂无
暂无

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

相关问题 如何检查情节提要中显示的视图 - how to check which view in storyboard are showing 如何确定滚动视图中当前可见的区域并确定中心? - How can I determine the area currently visible in a scrollview and determine the center? MVYMenuViewController:如何销毁从情节提要中实例化的视图控制器 - MVYMenuViewController: How to destroy a view controller which was instantiated from storyboard 如何使用我的操作并以编程方式过渡到故事板中定义的视图控制器? - How can I use my action and programmatically transition to a view controller as defined in the storyboard? 如何确定视图控制器 - how to determine view controller 我如何知道我的appdelegate当前正在显示(在视图中)哪个viewController? - How can I know which viewController is being displayed(in view) currently by my appdelegate? 如何确定哪个tabbar索引是我的视图控制器 - how to determine which tabbar index is my view controller iPhone如何确定以前的视图控制器支持的方向 - iPhone How to determine which orientations the previous view controller supports 如何在故事板中使用原型单元与搜索结果控制器 - How can i use prototype cell in storyboard with search result controller 对于iPhone,如何从当前加载的视图引用根视图控制器,因此可以替换/切换视图 - For Iphone how to reference root view controller from currently loaded view, so view can be replaced/switched
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM