Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Observing a UISlider's value - iPhone KVO

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?

like image 952
Dimitris Avatar asked Sep 27 '09 00:09

Dimitris


People also ask

What is KVO (key-value observing)?

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.

What is key-value coding in iOS?

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.

How do I use KVO to observe changes to a property?

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):

How to create a kvcodemo app in Xcode?

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.


1 Answers

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.

like image 133
Chris Parker Avatar answered Oct 02 '22 22:10

Chris Parker