views:

47

answers:

0

Hello

I am building a custom UINavigationController (Not subclassing it, I subclass UIViewController for this), I would like to have the instances of UIViewController that are added to my custom navigationController to get a reference to the custom navigation controller when they access the self.navigationController. I.e

You would, from a UIViewController that belong to a UINavigationController, do this to push a new view controller to the stack:

MyViewController *myVC = [[MyViewController alloc] init];
[self.navigationController pushViewController:myVC animated:YES];
[myVC release];

I would like to mimic this behavior. Preferably by a design pattern that does not involve adding code to the UIViewController it self. So in the above case when it is the custom navigation controller getting a controller pushed to it, it will, in the pushViewController method, set the navigationController to the custom controller (it self), so that when the newly added view controller does self.navigationController it will also get a reference to the custom nav-controller.

There are a few gotchas involved. Even though the added viewController is being displayed by the custom navigation controller the [self parentViewController] does not work when subclassing the UIViewController. If it did I could just go

[[self parentViewController] pushViewController...

from within my added UIViewController.

The self.navigationController is read-only so I can not set it manually and even if I could, I would have to set it to [self parentViewController] which I can't get to.

I had planned on building a category on the UIViewController (my project will only use the custom navigationController so no chance of things colliding). But his approach runs into the issue mentioned above, I have no way to get a reference to the Custom UINavigationController owning the pushed UIViewController, from within these added controllers. I would have to build protocols and set the CustomNavigationController as a delegate on each of the UIViewControllers, thus coupling it pretty strongly and making these UIViewControllers only function with my custom Nav-controller.

I hope it is clear what I am trying to achieve, I need some more design pattern experience in Objective C to see this one through on my own.

Thanks for any help/advise given:)