Why doesn#39;t Apple allow subclassing of UINavigationController? And what are my alternatives to subclassing?(为什么 Apple 不允许 UINavigationController 的子类化?我有什么替代子类化的方法?)
问题描述
我目前正在构建一个选项卡式 iPhone 应用程序,其中每个选项卡的视图控制器都是 UINavigationController
的一个实例,并且每个 UINavigationController
实例的每个子控制器都是一个UITableViewController
的实例.理想情况下,我想继承 UINavigationController
以便每个选项卡的控制器是 UINavigationController 的子类(除了具有所有标准 UINavigationController
功能,显然)服务作为与其子控制器关联的每个表视图的数据源和委托.尝试这样做似乎会破坏子类中的基本 UINavigationController
功能.
I'm currently building a tabbed iPhone application where each tab's view controller is an instance of UINavigationController
, and where every subcontroller of every one of the UINavigationController
instances is an instance of UITableViewController
. Ideally, I'd like to subclass UINavigationController
so that the controller for each tab is a subclass of UINavigationController that (in addition to having all the standard UINavigationController
functionality, obviously) serves as the datasource and the delegate for each of the table views associated with its subcontrollers. Trying to do this seems to break the basic UINavigationController
functionality in the subclass.
正如 Apple 在他们的 iPhone 文档中所说的那样,一个人不应该继承 UINavigationController
,而且事情似乎会中断,我想知道我应该如何扩展 UINavigationController's
没有子类化的功能,一般来说,在进行 Cocoa 开发时应该如何解决子类化限制.
Seeing as Apple says in their iPhone documentation that one shouldn't subclass UINavigationController
, and things seem to break when one does, I'm wondering how I should go about extending UINavigationController's
functionality without subclassing, and generally speaking, how one should work around subclassing limitations when doing Cocoa development.
谢谢!
推荐答案
作为参考,请注意从 iOS 6 开始,UINavigationController 可以被子类化合法.
For reference, note that since iOS 6, UINavigationController can be subclassed legally.
此类通常按原样使用,但在 iOS 6 及更高版本中可能是子类.UINavigationController 类参考
This class is generally used as-is but may be subclassed in iOS 6 and later. UINavigationController Class Reference
当然,这并不意味着您总是应该这样做.但你可以.
Of course, that doesn't mean you always should. But you can.
这篇关于为什么 Apple 不允许 UINavigationController 的子类化?我有什么替代子类化的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 Apple 不允许 UINavigationController 的子类化?我有什么替代子类化的方法?
基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01