【问题标题】:Access Current ViewController Class Name from AppDelegate.m从 AppDelegate.m 访问当前 ViewController 类名
【发布时间】:2013-07-24 03:50:52
【问题描述】:

如果我想访问当前视图控制器而不是根视图控制器以从 AppDelegate.m 中获取类名,该怎么办?

目前,ViewController A 实际上是 RootViewController 的根视图。

我在这里做了一些研究,但我只设法获得了 RootViewController 类名而不是 ViewController 类名。

NSLog of the current ViewController class name from AppDelegate.m

我遵循了为问题提供的答案,但它返回 null 自己。

NSLog(@"Current View Controller Class Name: %@", self.window.rootViewController.navigationController.visibleViewController.class);

NSLog(@"Current View Controller Class Name: %@", [self.window.rootViewController.navigationController.visibleViewController class]);

【问题讨论】:

  • 你在使用 UINavigationController 吗?
  • AppDelegate 类的 window 属性的视图控制器层次结构是什么。
  • @random 是的,我正在使用 UINavigationController... 因为我想在收到通知时检查当前的视图控制器类名。

标签: objective-c


【解决方案1】:

你试过了吗……

NSLog(@"Current View Controller Class Name: %@",NSStringFromClass(self.window.rootViewController.navigationController.visibleViewController.class));

【讨论】:

  • 是的!我之前尝试过,因为它返回 null 所以即使使用 NSStringFromClass 也肯定会返回 null。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-04
相关资源
最近更新 更多