【问题标题】:UIViewController's navigationController propertyUIViewController 的 navigationController 属性
【发布时间】:2013-12-19 23:00:57
【问题描述】:

我有一个扩展 UIViewController 的 X 类。令我惊讶的是,这个类可以有以下代码:

[self.navigationController popViewControllerAnimated:YES];

据我所知,navigationController 是 UINavigationController.h 中的类别添加的属性:

@interface UIViewController (UINavigationControllerItem)
@property(nonatomic,readonly,retain) UINavigationController *navigationController;  
@end

我的类扩展了 UIViewController,而不是 UINavigationController,而且我看不到这个类别被引用的方式。我以为我必须导入类别才能访问它声明的成员。那么 UIViewController 如何访问在另一个不相关的头文件中声明的属性呢?

谢谢, 亚诺斯

【问题讨论】:

  • 它已经通过添加“”为您导入,想想UINavigationController然后您是否导入了“UINavigationController.h”来使用UINavigationController? UIButton 怎么样? UILabel?...同样的事情..
  • 好的,非常感谢!我现在可以睡觉了;)

标签: ios objective-c uiviewcontroller uinavigationcontroller


【解决方案1】:

根据 Apple 文档 UIViewController 具有 navigationController 属性:

视图控制器层次结构中最近的祖先是导航控制器。 (只读)。 如果接收器或其祖先之一是导航控制器的子级,则此属性包含拥有的导航控制器。如果视图控制器未嵌入导航控制器,则此属性为零。

请参阅 UIViewController 文档。

【讨论】:

  • 谢谢 yursol,但我的问题本质上更笼统。我不明白如何在不明确引用引入它的类别的情况下引用属性或方法。正如 shaik 在上面的评论中指出的那样,它是通过 UIKit/UIKit.h 导入间接引用的。谢谢,杰诺斯
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-11
  • 1970-01-01
相关资源
最近更新 更多