navigationController属性在UINavigationController.h中声明,但它是UIViewController的属性 [英] navigationController property is declared in UINavigationController.h but is a property of UIViewController

查看:48
本文介绍了navigationController属性在UINavigationController.h中声明,但它是UIViewController的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Ios开发的新手,我正在阅读Big nerd书来学习它.我对"navigationController"感到困惑.例如,在我的类中,它是 UITableViewController 的实例(也与 UIViewController 的任何子类相同),我有:

I am new to Ios development and I am following the Big nerd book to learn it. I have a confusion over the "navigationController". for instance in my class that is an instance of UITableViewController (same for any subclass of UIViewController as well) I have this :

[[self navigationController]
     pushViewController:detailViewController
     animated:YES];

当我查看苹果文档时,此 navigationController 似乎是 UIViewController 的属性,但据说它是在 UINavigationController.h !我打开了 UIviewcontroler.h ,并且没有 navigationController 的属性或方法,但是正如文档所述,它确实存在于 UINavigationController.h

when I look at apple documentation this navigationController seems to be a property of UIViewController, but is said that it is declared in UINavigationController.h ! I opened the UIviewcontroler.h and there is no property or method for navigationController, but as the documentation says it is indeed in UINavigationController.h

这根本没有意义.首先,我知道一个子类继承了父类的属性和方法,但是 UITableViewControler 绝不是 UINavigationController 的子类,而是UiViewController的子类.所以希望有人能理解我的要求.不从 UINavigationController 继承时,如何访问此属性?以及文档如何将其显示为 UiViewController 的属性?

it does not make sense at all . first of all I know that a child class inherits the property and methods of the parent class, but UITableViewControler is by no mean a subclass of UINavigationController ,but a child of UiViewController . So hopefully some one understand what I am asking. How I am able to access to this property when I am not inheriting from UINavigationController ? and how the documentation can show that as a property of UiViewController ?

推荐答案

UINavigationController.h包含一个UIViewController类别,该类别声明了 navigationController 属性.

UINavigationController.h includes a UIViewController category that declares a navigationController property.

请记住,文件名只是约定-它们实际上对语言没有任何意义.文件中的代码很重要.仅仅因为某些代码位于UINavigationController.h中,并不意味着它位于UINavigationController类中.头文件属于"一个类完全可以自由地在其他类上声明类别,以帮助它们与头所关注的类进行交互.

Remember, filenames are just conventions — they don't actually mean anything to the language. The code inside the files is what matters. Just because some code is inside UINavigationController.h doesn't mean it's inside the UINavigationController class. A header file "belonging" to one class is perfectly free to declare categories on other classes to help them interact with the class that the header is focused on.

这篇关于navigationController属性在UINavigationController.h中声明,但它是UIViewController的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆