Ash
Ash

Reputation: 9351

How to communicate between objects

Still having trouble with this language.

Ok, let's say I have two objects. The first is my application delegate, the second is a custom view containing the various buttons that make up the main menu. When a button is clicked, it is the menu that responds. However, I need to make use of certain instance variables in the application delegate (such as the Window) in order to implement the appropriate changes. In this case, I want the main menu to be removed and replaced with a new view. In other words, the main menu needs to trigger a method held in the application delegate.

So, how should I go about this?

Upvotes: 2

Views: 145

Answers (2)

BP.
BP.

Reputation: 10083

I did a blog post on my web site a ways back that distills the process down into the simplest way I could come up with to describe setting up a delegate.

http://www.dosomethinghere.com/2009/07/18/setting-up-a-delegate-in-the-iphone-sdk/

Upvotes: 5

ksoderstrom
ksoderstrom

Reputation: 489

The preferred way is to create a delegate protocol for your view controller. Your application delegate can then implement this protocol and act on behalf of your view controller.

Check out the part about Delegation in the Cocoa Fundamentals Guide. Also read through the docs about Modal View Controllers, as this is quite similar to what you're trying to do. There are some code examples there as well.

Upvotes: 3

Related Questions