Rép : Enabled Binding and Array Controllers
Rép : Enabled Binding and Array Controllers
- Subject: Rép : Enabled Binding and Array Controllers
- From: Pierre Molinaro <email@hidden>
- Date: Fri, 8 Feb 2008 10:44:15 +0100
I think you can bind to canRemove controller key, leaving model key
path empty.
Bind to: ArrayController
Controller Key: canRemove
Model Key Path: (empty)
Oops, I realize that the above code works only if "Avoid Empty
Selection" array controller option is set.
I suggest the following code : subclass NSArrayController, observe
"arrangedObjects" property, and manually trigger change of a
"isNotEmpty" boolean attribute.
@interface MyArrayController : NSArrayController {
}
@end
@implementation MyArrayController
- (void) didChangeValueForKey: (NSString *) inKey {
[super didChangeValueForKey:inKey] ;
if ([inKey isEqualToString:@"arrangedObjects"]) {
[self willChangeValueForKey:@"isNotEmpty"] ;
[self didChangeValueForKey:@"isNotEmpty"] ;
}
}
- (BOOL) isNotEmpty {
return [[self arrangedObjects] count] > 0 ;
}
@end
In interface builder, set array controller class to MyArrayController;
For enabled binding :
Bind to: ArrayController
Controller Key: isNotEmpty
Model Key Path: (empty)
Pierre
_______________________________________________
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