View Full Version : KVO/KVC Help!
Jun 25, 2009, 04:47 PM
I created a KVO-compliant class that is bound to certain textfields in a window. This class simply stores the data. Another class has an instance of it, and added itself as an observer. However, my breakpoint in the implementation of
does not get triggered when I update the fields.
Jun 25, 2009, 09:03 PM
If it helps, I can post more code.
myController = [[MyController alloc] init];
NSArray *allValues = [NSArray arrayWithObjects:@"aKey", @"anotherKey" ,nil];
for(int i=0; i<[allValues count]; i++)
options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
NSArray *allValues = [NSArray arrayWithObjects:@"aKey",@"anotherKey",nil];
MyController: has properties named aKey and anotherKey as floats, bound to textfields on a window. (thinking back, this is probably better descried as a model class)
currentSelection: Another controller class that takes the data in a dictionary and updates both model and view objects
self: has references to currentSelection and myController. It is basically the "main" Class (it has references to many controllers, but few models and views)
I know, I know, my MVC is a little twisted. But that shouldn't interfere with my KVC!!!
Help would be very much appreciated
Jun 26, 2009, 12:19 AM
I have read up more on KVO/KVC, and it seems that my code does comply. I check to make sure that the code that adds self as an observer is run, and it is.
Does myController have to have NSNumbers as apposed to floats?
In a xib Binding, would a change notify observers?
Do I need to subclass methods in myController?
To prove that I am trying, I can show the references I have tried to use:
Thank you in advance, if you help.
Jun 26, 2009, 12:24 AM
What do your setters look like in MyController? Are you using @properties or using your own custom methods? If the latter you probably need to implement willChangeValueForKey: and didChangeValueForKey:
Jun 26, 2009, 12:25 AM
I use @property, then synthesize.
I find that is best to reduce code and possible error.
Jun 26, 2009, 11:11 AM
After your suggestion, I thought that maybe it would work to make my own accessor methods and make those calls myself, but that did not work.
Is it possible that my Interface Building is bad?