MB.
MB.

Reputation: 4211

Objective C best practices when using Interface Builder for controller communication?

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.)

Upvotes: 2

Views: 250

Answers (1)

Strong Like Bull
Strong Like Bull

Reputation: 11297

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.

Upvotes: 2

Related Questions