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 的子类化?我有什么替代子类化的方法?


- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01