【问题标题】:How to find UIViewController is in active or inactive iPhone app?如何查找 UIViewController 处于活动或非活动 iPhone 应用程序中?
【发布时间】:2012-08-10 18:35:34
【问题描述】:

我正在使用基于 tabBar 的 iPhone 应用程序。

  • 标签栏控制器中有 5 个 UIViewController。
  • 在我的应用程序中,我使用了 APNS。收到 APNS 后,我想更新 UIViewController 4 中的数据。
  • 如果用户在UIViewControllers 1,2,3 和 5 中工作,我想更新UIViewController4 中的数据并显示徽章。
  • 我刷新并更新了 UIViewController 4 中的数据,但如果用户不在 UIViewController 4 中,我想显示徽章。
  • 如果用户当前在UIViewController 4 我不想显示徽章。

我如何从其他UIViewController 中找到另一个UIViewController 处于活动或非活动状态?

编辑

我试过下面的代码来获取UITabBarController的selectedIndex。

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"%d", appDelegate.tabBarController.selectedIndex);

【问题讨论】:

  • 你不能用标签栏的'selectedViewController'属性来获取它吗?

标签: iphone ios uinavigationcontroller uitabbarcontroller badge


【解决方案1】:

由于您正在使用UITabBarController,您可以轻松地询问当前选择的选项卡,这应该会导致活动视图控制器。尝试以下方法: selectedViewControllerselectedIndex

【讨论】:

  • 感谢您的参考。我试图获取 selectedIndex 但 selectedIndex 的值没有更新。它返回先前选择的选项卡索引。你能给我建议吗?谢谢。
猜你喜欢
  • 2013-05-08
  • 1970-01-01
  • 2015-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-19
  • 1970-01-01
相关资源
最近更新 更多