By default, when I observe the value of a UISlider, it only updates once, when the slider is clicked, not continuously, even thought that is the slider's setting. Is there a way to get the continuous value change of the slider?
Key-Value Observing (KVO) is related directly to another powerful and important mechanism, named Key-Value Coding, or KVC. Actually, any property you want to observe for changes must be Key-Value Coding compliant, but we will talk more about that later.
Here is the definition of the Key-Value Coding according to Apple’s official documentation: Key-value coding is a mechanism for accessing an object’s properties indirectly, using strings to identify properties, rather than through invocation of an accessor method or accessing them directly through instance variables.
Open the ViewController.m file, and go to the viewWillAppear: method. The first step in KVO is to always observe for the desired property, so add the next line at the end of the method (we will observe only for changes to the siblings array of the child1 object):
So, the first step is to create a new project, therefore go and launch Xcode and select to create a new project. To the guide that appears, select the Single View Application template, in the Application category under the iOS section. Proceed to the next step, and in the Product Name field set the KVCODemo name.
UIKit doesn't actively support KVO. You may be getting lucky in that some notifications may make it through the usual mechanisms, but for the most part you shouldn't assume you can use KVO with any UIKit class.
You should instead get your continuous events through the UISlider's associated target's action method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With