Re: NSArrayController nib binding vs code binding
Re: NSArrayController nib binding vs code binding
- Subject: Re: NSArrayController nib binding vs code binding
- From: Trygve Inda <email@hidden>
- Date: Mon, 18 Jul 2011 19:13:05 -0700
- Thread-topic: NSArrayController nib binding vs code binding
> 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 (email@hidden)
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:
This email sent to email@hidden