> On Jul 18, 2011, at 18:41, Trygve Inda wrote: > >> The other possibly related issue is that I have my table delegate defined in >> the nib and seem to get >> >> -(void)tableViewSelectionDidChange:(NSNotification *)aNotification >> >> Before awakeFromNib which means my binding has not taken place yet. Do I >> need to set the delegate in awakeFrmNib rather than in the nib directly? > > Assuming there's nothing else going here that you haven't mentioned, I can't > see any reason why you shouldn't bind the array controller in the nib file, > even if the thing being bound to is being created programmatically. > > If you do that, I hope you'll immediately see that the *real* problem is a > lack of KVO compliance in your data model. You essentially have a data model > property "myClassInstance" (in effect, since you probably don't have an actual > property for this), but you're not providing KVO compliance for that property. > If you didt, it wouldn't matter if it was nil (i.e. you hadn't created it yet) > at the time the binding happened, but when you finally did get around to > creating it the KVO compliance would inform the array controller that its > content had changed. > > Does that make sense? I'm not sure I explained myself very well. I'm saying > you attended to the KVO compliance to the "places" property of MyClass, but > you didn't attend to KVO compliance of a necessary "myClassInstance" property > of whatever creates it. > > (If you take the trouble to get the KVO compliance right *everywhere*, the > payoff is that all of those irritating timing problems around nib loading are > non-problems.)
Where am I not KVO compliant? More details... I have a class "MyClass" which implements: // Required CollectionPlaces Accessors (Get) -(NSUInteger)countOfPlaces; -(id)objectInPlacesAtIndex:(NSUInteger)index; -(NSArray *)placesAtIndexes:(NSIndexSet *)indexes; -(void)getPlaces:(id *)aBuffer range:(NSRange)aRange; // Required Collection Accessors (Set) -(void)insertObject:(id)anObject inPlacesAtIndex:(NSUInteger)index; -(void)insertPlaces:(NSArray *)objects atIndexes:(NSIndexSet *)indexes; -(void)removeObjectFromPlacesAtIndex:(NSUInteger)index; -(void)removePlacesAtIndexes:(NSIndexSet *)indexes; -(void)replaceObjectInPlacesAtIndex:(NSUInteger)index withObject:(id)anObject; -(void)replacePlacesAtIndexes:(NSIndexSet *)indexes withPlaces:(NSArray *)objects; Internally MyClass keeps an array to hold objects of another class. MyClass is a subclass of NSObject so I am not sure how to correct " but you didn't attend to KVO compliance of a necessary "myClassInstance" property of whatever creates it." The only issue with the tableViewSelectionDidChange is that in that method I have something like: if ([[itemsController selectedObjects] count]) { MyOtherClass* item = [[itemsController selectedObjects] objectAtIndex:0]; .... } "item" is valid, but is not initialized with valid data because the binding from the Array does not seem to have happened when I get to this point. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com