Re: Custom Enable Binding
Re: Custom Enable Binding
- Subject: Re: Custom Enable Binding
- From: Sanjay Samani <email@hidden>
- Date: Tue, 13 Mar 2007 17:12:32 +0000
I have never had success adding controller keys to object controller
subclasses. The controller API's are pretty opaque, so it's hard to
know whether you are tromping on the controller's operation.
I was hoping that using standard Cocoa paradigms and not overriding
anything in the Array Controller, just extending it I would be OK!
In any case, the canMapSelectedElements logic should probably go
into your model class, if you have one. I doubt you will be able to
get what you want from the controller subclass.
Unfortunately the code can't sensibly go in the model class. The
business logic is the user is trying to map two user-selected elements
together. They can only be mapped if they have the same data type.
An alternative could be to make the custom controller the delegate
of the table view (you may also need an outlet) and implement -
tableViewSelectionDidChange. If your method needs to know what is
selected, you may need to call -selectedRowIndexes on the tableview
if the controller doesn't seem to know its selection yet. I have
found that some actions are performed with a delay so aren't
available immediately in code. Which do this, and under what
circumstances, is not documented AFAIK.
I managed a hack to get it to work in the ArrayController, which is :
-(void)awakeFromNib;
{
//... other initialisation
[self addObserver:self forKeyPath:@"selectionIndexes"
options:NSKeyValueObservingOptionNew context:NULL];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context;
{
if ((self == object) && [keyPath isEqual:@"selectionIndexes"])
{
[self willChangeValueForKey:@"canMapSelectedElements"];
[self didChangeValueForKey:@"canMapSelectedElements"];
}
}
But I thought the whole point of
+setKeys:triggerChangeNotificationsForDependentKey: was to trigger the
change notification for the dependent key so I don't have to do it
explicitly! If I can't do it the way I originally tried, I'll just do
the same thing in my custom view controller, rather than muddy the
ArrayController subclass.
Sanjay
___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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