Sean Danzeiser
Sean Danzeiser

Reputation: 9243

Adding UINavigationController functionality to a container controller with a defined Protocol

I've designed a custom container view controller that mimics the functionality of something like path or facebook (the sliding deck effect). In order to communicate with those controllers, I've defined a protocol that allows ask them for some info/ alert them to some events.

Now, i've decided I'd like one of these child view controllers to be embedded in a navigation controller. Unfortunately, The navigation controller is now receiving those protocol methods and I'm getting a crash.

My temporary solution is to create an intermediary method that asks whether the controller i want to talk to is infact a navigation controller, and if it is, send the message to the root.

Is there any more graceful way of doing this? It seems like code smell to have to write an 'in between' method that performs this check for every single protocol method in my base controller. Any thoughts??

thanks

Upvotes: 1

Views: 265

Answers (2)

zinc1oxide
zinc1oxide

Reputation: 490

Have you tried embedding the parent view controller within a NavigationController instead of a specific child controller? By doing this, you effectively allow all child controllers to participate within the navigation. This will allow you to properly utilize your protocol.

Upvotes: 2

Simon Goldeen
Simon Goldeen

Reputation: 9080

Sounds like you need to set your up your child view controller with a delegate and send its messages to its delegate rather than its parent.

If you don't know about delegates: Cocoa Fundamentals Guide

Upvotes: 0

Related Questions