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
There are three ways of doing this:
- 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.
- 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.
- 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.
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.
精彩评论