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.


public virtual void AddObserver (NSObject observer, NSString keyPath, NSKeyValueObservingOptions options, IntPtr context)


The object that will receive the notifications
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.
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.
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 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,
        Player.AddObserver (this, (NSString)”volume",
            NSKeyValueObservingOptions.Old | NSKeyValueObservingOptions.New,

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


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