Discussion in 'Mac Programming' started by Duke Leto, Jun 25, 2009.

  1. macrumors regular

    Mar 17, 2008
    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.
  2. thread starter macrumors regular

    Mar 17, 2008
    If it helps, I can post more code.

    - (void)initializeMyController
    	myController = [[MyController alloc] init];
    	NSArray *allValues = [NSArray arrayWithObjects:@"aKey", @"anotherKey" ,nil];
    	for(int i=0; i<[allValues count]; i++)
    		[myController addObserver:self
    						   forKeyPath:[allValues objectAtIndex:i]
    							  options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
    	NSArray *allValues = [NSArray arrayWithObjects:@"aKey",@"anotherKey",nil];
    	if([allValues containsObject:keyPath])
    		[currentSelection updateDataFromDictionary:change];
    	[super observeValueForKeyPath:keyPath
    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
  3. thread starter macrumors regular

    Mar 17, 2008
    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.
  4. Moderator emeritus


    Jun 15, 2000
    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:
  5. thread starter macrumors regular

    Mar 17, 2008
    I use @property, then synthesize.
    I find that is best to reduce code and possible error.
  6. thread starter macrumors regular

    Mar 17, 2008
    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?

Share This Page