Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Apple allow subclassing of UINavigationController? And what are my alternatives to subclassing?

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.

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.

Thanks!

like image 354
Matthew McCroskey Avatar asked Dec 21 '09 00:12

Matthew McCroskey


2 Answers

Why on earth do you want the UINavigationController to act as a datasource for the table? The whole point of UITableViewController is that you subclass it, and it acts as the datasource for the UITableView that it also places in, and fills, the parent view.

like image 92
U62 Avatar answered Oct 10 '22 15:10

U62


For reference, note that since iOS 6, UINavigationController can be subclassed legally.

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.

like image 23
Remy Vanherweghem Avatar answered Oct 10 '22 13:10

Remy Vanherweghem