为什么 Apple 不允许 UINavigationController 的子类化?我有什么替代子类化的方法? [英] Why doesn't Apple allow subclassing of UINavigationController? And what are my alternatives to subclassing?

查看:19
本文介绍了为什么 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 的子类化?我有什么替代子类化的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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