NSArrayController's canRemove controllerkey and toolbar items problem
NSArrayController's canRemove controllerkey and toolbar items problem
- Subject: NSArrayController's canRemove controllerkey and toolbar items problem
- From: Sacha <email@hidden>
- Date: Fri, 12 Sep 2008 18:52:03 +0200
Hi,
I ran into a problem where the canRemove controllerkey doesn't correctly
disables a toolbar item.
What I first had, was a simple toolbar item, who's enabled property was
bound to the canRemove controllerkey of an arraycontroller in my nib, and
that sent an action to the same arraycontroller when clicked with the
message remove.
So far I got it working perfectly.
I extended it using a sheet to avoid accidental clicks. So I made a
controller class (more or less the same as in the documentation from ADC):
@interface DeleteRecordConfirmationSheet : NSObject {
IBOutlet NSWindow *targetWindow;
IBOutlet NSArrayController *entryArray;
}
- (IBAction)deleteSelectedBlogEntry:(id)sender;
@end
@implementation DeleteRecordConfirmationSheet
- (IBAction)deleteSelectedBlogEntry:(id)sender
{
NSBeginAlertSheet(@"Do you really want to delete the selected entry?",
@"Remove",
@"Cancel",
nil,
targetWindow,
self,
@selector(sheetDidEndShouldDelete:returnCode:contextInfo:),
nil,
nil,
@"There is no undo for this operation.");
}
- (void)sheetDidEndShouldDelete:(NSWindow *)sheet returnCode:(int)returnCode
contextInfo:(void *)contextInfo
{
if (returnCode == NSAlertDefaultReturn)
{
[entryArray removeObjects:[entryArray selectedObjects]];
}
}
@end
Pretty simple and straightforward.
ToolbarItem bound to canRemove controllerkey, and sentaction to the
controller class, outlets bound to my window and arraycontroller
respectively.
It works fine for deleting the the array objects, but the toolbaritem isn't
disabled anymore (while it did work correct not using the controller).
For instance, when I add an item, press remove, confirm, it "flickers"
disabled and immediately is enabled back again (while the array is empty).
If no arrayobject is selected (using a table view) even with when the list
is not empty, it is enabled.
For testing, I placed a simple pushbutton on my window contentview, bound it
to the controllerkey and arraycontroller and it just enables/disables
perfectly (asynchronously with the toolbaritem not working).
I can't help it finding this behaviour strange...
Nothing found on google about somebody having a similar problem either...
Greets.
_______________________________________________
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