I would like a way for my viewcontroller which has a subview in it, which is it’s own class, to find out when a property in this class changes. How do i do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
KVO – key value observation. See the documentation here
KVO is really neat when you have some central data that can be modified in various places and might have different views that need to refresh when a value updates. It’s probably perfect for your requirements. The documentation is comprehensive and has lots of examples.
EXAMPLE:
If we want to know when theClass.propertyName changes, we can add an observer like this;
Then you need to implement the following method that will receive the notifications when there is a change.
DO read the documentation though, it explains it all much better.