Key-value observing

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Key-value observing

Dear all,

I tried to use "Key-value observing" pattern ""
at my iphone application but my problem is that the "ObserveValue" method was invoked only at property initialization time but didn't feel with any extra changes of it even I assign "NSKeyValueObservingOptions" enum to New,Old and OldNew.

Here is part of my project:
I assume the scenario of person and bankAccount; BankAccount object must notify person if "AccountBalance" property changed.

Person class:
public class Person:NSObject
              public Person () {}
              public override void ObserveValue (NSString keyPath, NSObject ofObject,NSDictionary  change, IntPtr context)  { //Do somthing }

Bank account class:
public class BankAccount:NSObject
               public BankAccount () {}

               public override void SetValueForKey (NSObject value, NSString key)

              public void setAccountBalance(int accountBalance)

             public int getAccountBalance()
                        {return accountBalance;}
            private int _accountBalane;

            [Export ("accountBalance")]
            public int accountBalance
                       get{return _accountBalane;}


Main class:
public partial class AppDelegate:UIApplicationDelegate
Person person=new Person();
BankAccount bankAccount=new BankAccount();

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
 bankAccount.AddObserver(person,new NSString("AccountBalance"),NSKeyValueObservingOptions.New |


bankAccount.SetValueForKey(new NSNumber(100),new NSString("AccountBalance"));


Thanks for reading and sorry for this long post.
Does anyone have any help?