MonoTouch.Foundation.NSObject.AddObserver Method
Registers an object for being observed externally (using NSString keyPath).   Observed changes are dispatched to the observer’s object NSObject.ObserveValue method.

Syntax

[MonoTouch.Foundation.Export("addObserver:forKeyPath:options:context:")]
public virtual void AddObserver (NSObject observer, NSString keyPath, NSKeyValueObservingOptions options, IntPtr context)

Parameters

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 MonoTouch.Foundation.NSObjectObserveValue method when one of the properties change.
context
Opaque constant that will be passed to the NSObject.ObserveValue method

Remarks

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 MonoTouch.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);
        }
    }
}

Requirements

Namespace: MonoTouch.Foundation
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0