chris P chris P - 9 months ago 42
iOS Question

How can I check if my NavigationController subclass has had VC's pushed & popped?

This Apple Doc looks promising, but they are not getting called.

I have a CustomNavigationController that inherits from UINavigationController. I need to know when a VC has been pushed or popped from my CustomNavC.

I can conform to UINavigationControllerDelegate, but this seems to be more for ViewControllers. Not for the CustomNavC to do a

self.delegate = self

How can this be achieved?

UPDATE: False alarm. Sorry all. I was testing on device and had OS_ACTIVITY_MODE disabled. The UINavigationControllerDelegate functions work just fine.

Answer Source

One option is to override the pushViewController and popViewController methods.

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    [super pushViewController:viewController animated:animated];

    // Handle push as needed

There are several pop... methods you can override as well.

You may also wish to override the setViewControllers:animated: method which is called when the whole stack is replaced.

Overriding these methods leaves the delegate free to be used by other classes.