2

According to

What's the best way to communicate between view controllers?

best practices for communication between ViewControllers is to inject your dependencies into the stack. And not to use delegate.

How do you do that when using Interface Builder? For example I have a *navController variable in AppDelegate. I'd like to work with that variable in a TableView down the line. How do I access the *navController variable from the TableView class? Is there a way to inject it?

(I know I can use [self.navigationController] in this particular case but I'm asking from a general point of view.)

Community
  • 1
  • 1
MB.
  • 4,167
  • 8
  • 52
  • 79
  • Why are you having controller variables in App delegate? Also please accept more answers so people are motivated to help you out. – Strong Like Bull May 11 '11 at 20:24
  • @jini: I was trying to create a use-case. The simplest form of the question is How do you communicate between ViewControllers when using Interface Builder? Do the concepts from the post I linked to apply or should I use delegates. – MB. May 11 '11 at 20:51

1 Answers1

2

Think of delegates as a nanny. You have to tell your nanny if you are done playing, eating, watching TV ETC. With that concept in mind, you can communicate with other controllers in terms of notifying your "nanny" so she can do something about it. However if you are just wanting to communicate with another controller, I typically import that controller class in question and cast a pointer. Depends if I want the delegate to do something about it or not.

Strong Like Bull
  • 11,155
  • 36
  • 98
  • 169