1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

KVO selectedobjects

Discussion in 'Mac Programming' started by MrFusion, Oct 28, 2009.

  1. macrumors 6502a

    I am breaking my head over KVO.

    This is part of a NSArrayController subclass. I have to check when its selection changes and then do something with it.
    Its parent class has the same code, but checks for arrangedObjects instead of selectedObjects.
    The problem is that it works for arrangedObjects but not for selectedObjects. The documentation does say that selectedObjects adheres to KVO.

    Any ideas as to the possible cause of this problem?

    -(id) initWithCoder:(NSCoder *)decoder {
    	//init method for classes loaded from nib
    	self = [super initWithCoder:decoder];
    	if (self != nil) {
    		[self addObserver:self
    				  context:NULL]; //register for notification of new objects
    	return self;
    #pragma mark -
    #pragma mark cache
    - (void)observeValueForKeyPath:(NSString *)keyPath
                            change:(NSDictionary *)change
                           context:(void *)context {
    	if ([keyPath isEqual:@"selectedObjects"]) { //selectedObjects
    		id selectedObject = [[self selectedObjects] myFirstObject];
    		// do something with selectedObject
    	// be sure to call the super implementation
    	// if the superclass implements it
    	[super observeValueForKeyPath:keyPath

Share This Page