【问题标题】:obtaining UINavigationController in an UIView在 UIView 中获取 UINavigationController
【发布时间】:2011-09-26 09:38:38
【问题描述】:

我正在使用的自定义标签栏控制器应用 ViewController 或 UINavigationController,如下所示:UIViewController* viewController = [data objectForKey:@"viewController"];

我不知道它是如何工作的,但“viewController”作为 UINavigationController 出现。接下来,自定义标签栏控制器类添加一个像这样的标签,viewController.view.tag = THE_TAG;

检索控制器是使用UIView* currentView = [self.window viewWithTag:SELECTED_VIEW_CONTROLLER_TAG];

这部分是我感到困惑的地方,因为现在当我 nslog 时 “currentView”我得到一个 UILayout 等......而不是我的 UINavigationController。我假设它将标签应用于包含导航控制器的 UIView?

如何在这个 UIView 中引用 UINavigationController?

【问题讨论】:

  • 在我看来,如果UIView 需要联系任何类型的UIViewController,这是一个糟糕的设计。应该反过来,或者让他们通过协议进行交谈。

标签: iphone ios cocoa-touch


【解决方案1】:

在上面什么是THE_TAG,你能确认它是唯一的吗(即不为零,并且不匹配在其他地方被相同机制使用的东西)?

我会非常谨慎地过度使用 tag,因为没有简单的方法来获取全局唯一标签,并且当使用 self.window viewWithTag 之类的东西时,您几乎可以看到应用程序中的每个视图都被检查。

【讨论】:

    【解决方案2】:

    您似乎对 viewviewController 感到困惑。 UINavigationController 是 UIViewController 的子类。它不是 UIView 的子类。 UIViewControllers 确实有一个属性,它是一个 UIView 类。当您使用 viewWithTag: 时,您可能正在访问此属性。所以也许,当您使用该方法时,您访问的不是 UINavigationController,而是 UINavigationController 的 view 属性(这实际上是您可能不应该弄乱的东西。)

    【讨论】:

      猜你喜欢
      • 2020-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多