Can anyone explain why it’s not possible to create your own view controller hierarchies using UIKit on the iPhone?
Let me explain: when creating applications using a complex view hierarchy and navigation logic, it’s a good idea to have certain views controlled by a dedicated view controller. These controllers can have their own subcontrollers, and so on. All standard stuff really.
So why is the parentViewController property readonly? It’s used by UINavigationController and UITabBarController, and many other properties rely on it (for example the navigationController property).
I’ve seen many people telling us to create our own property for managing view controller hierarchies, but that’s a little silly when Apple’s own framework uses its own private “you can’t touch it” hierarchy model.
Readonly properties are usually properties that an instance must have set all the time to avoid serious problems.
In this case of a navigable hierarchy, child controllers must be able to have access to the parent controller at all times. (This is trait defines the actual navigation hierarchy i.e. you can back out of subviews.) If the property is readwrite it might not be set,might not be set correctly or might suddenly change all of which would orphan the controller. That is unacceptable in the API upon which the entire platform depends.
Why risk making the API more fragile just to handle a rare design case? It’s easy enough to roll your own for the rare circumstance in which you want a flexible hierarchy.