Key Value Binding does existing in iOS, but you have to do it manually. You can create a class derived from "Button" and you can create a property of NSDictionary which you can assign and at time of assigning, you can start observing changes in dictionary instance, and in the delegate you can read value and assign to self.
Ok here is my button.h file
@interface MyCustomButton : NSButton
NSDictionary* store;
@end
-(NSDictionary*) store;
-(void) setStore: (NSDictionary*) v;
and here is my button.m file
@implementation MyCustomButton
-(void) dealloc{
[self setStore: nil];
[super dealloc];
}
-(void) loadValues:{
// fill your loading values here
// this is not correct you may need
// to see help to get correct names of
// function
[self setText: [store stringForKey:@"buttonLabel"]];
}
-(void) setStore: (NSDictionary*) v{
if(store!=nil){
[store removeObserver: self forKeyPath:@"buttonLabel"];
[store removeObserver: self forKeyPath:@"buttonX"];
[store removeObserver: self forKeyPath:@"buttonY"];
[store release];
}
if(v==nil)
return;
store = [v retain];
[store addObserver: self forKeyPath:@"buttonLabel" options:0 context:nil];
[store addObserver: self forKeyPath:@"buttonX" options:0 context:nil];
[store addObserver: self forKeyPath:@"buttonY" options:0 context:nil];
[self loadValues];
}
-(NSDictionary*) store{
return [store autorelease];
}
-(void) observeValueForKeyPath: (NSString*) keyPath
ofObject:(id)object
change:(NSDictionary*)change
context:(void*)context{
// here you can identify which keyPath
// changed and set values for yourself
[self loadValues];
}
@end
and probably in the beginning of code or whereever you have instance of MyButton you need to do following...
MyButton* button = [[[MyButton alloc] init] autorelease];
// add button to view...
[button setStore: myDictionary];
// from this point onwards button will automatically
// change its properties whenever dictionary
// is modified