views:

38

answers:

2

Hello all,

I have a view controller which gets an NSObject conforming to a protocol and then displays a view with the object's properties.

The question : How can my controller know that a property of this object has been modified and then refresh the view ?

Thanks a lot

Thierry

+2  A: 

There are three ways of doing this:

  1. Have the object call a method in the controller in response to an event e.g. a user clicking the button. This is usually done using an IBAction.
  2. Set the controller to be the delegate of object e.g. a UIWebView sends a message to its delegate when it finishes loading a page.
  3. Use a notification. The object generates the notification and then one or more objects (including the controller) registers to listen for the notification. This is usually not used with interface elements although it can be.

I can't tell you more without more detail about the specifics of your project.

TechZen
A: 

Your viewcontroller should conform to your . In your model, all your set methods should trigger appropriate functions you define in your modelchangedprotocol. This OO design pattern is also known as "Observer" design pattern.

Mugunth Kumar