- observer
- The object that will receive the notifications
- keyPath
- Key-path to use to perform the value lookup. The keypath consists of a series of lowercase ASCII-strings with no spaces in them separated by dot characters.
- options
- Flags indicating which notifications you are interested in receiving (New, Old, Initial, Prior).Context data passed to the Foundation.NSObjectObserveValue method when one of the properties change.
- context
- Opaque constant that will be passed to the NSObject.ObserveValue method
When the object is registered for observation, changes to the object specified in the keyPath that match the flags requested in options will be sent to the Foundation.NSObjectObserveValue method in the observer object.
To stop receiving notifications, call the NSObject.RemoveObserver method.
c# Example
class MySampleViewController : UIViewController { // A token to tell different observed properties appart. const IntPtr tokenObserveRate = (IntPtr) 1; const IntPtr tokenObserveVolume = (IntPtr) 2; void Setup () { Player.AddObserver (this, (NSString)"rate", NSKeyValueObservingOptions.Old | NSKeyValueObservingOptions.New, tokenObserveRate); Player.AddObserver (this, (NSString)”volume", NSKeyValueObservingOptions.Old | NSKeyValueObservingOptions.New, tokenObserveVolume); } public override void ObserveValue (NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr ctx) { // Handle change. if (ctx == tokenObserveRate) { // the rate changed } else if (ctx == tokenObserveVolume){ // the volume changed } else { // invoke the base implementation for unhandled events base.ObserveValue (keyPath, ofObject, change, ctx); } } }