Re: activating Delete menu item through binding
Re: activating Delete menu item through binding
- Subject: Re: activating Delete menu item through binding
- From: Koen van der Drift <email@hidden>
- Date: Sat, 21 Apr 2012 22:18:49 -0400
On Apr 16, 2012, at 7:34 PM, Quincey Morris wrote:
> Yes, that's an awkward case. Although a NSViewController *is* a responder, it *isn't* automatically added to the responder chain. Therefore it cannot be found as first responder, and so its action method is not recognized by menu validation. :)
>
> You can manually add the view controller to the responder chain if you want, in loadView perhaps. However, I've never quite figured out all the places where I'd need to manually remove it again. (If you're not swapping views, then maybe you don't need to worry about that -- just leave it there until the responder chain gets pruned in the normal course of events.)
>
> Otherwise, you have to move the validation code to the window controller (or whatever object can receive the validation request), *and* put a duplicate 'delete:' action method in the window controller, *and* have it call the view controller's 'delete:' method.
>
> Another alternative might be to implement 'delete:' in the view itself (if you can use/are using a custom view subclass), and delegate both the validation and the invocation to the view controller.
>
> Sorry, I don't know of a cleaner way. Maybe someone else will jump in with an improved solution.
So, I solved it as follows. I created a deleteObjects IBAction in my AppController class invoked by the delete menuItem. To remove the objects, I am more or less following the code in Hillegass' book, chapter 15 on NSAlerts. In this example, the line
[employeeController remove: nil] is used to remove the selected objects (employees)
However in my app it didn't remove anything (the code was called, though). After some searching, I ended up doing the following:
for (Employee *employee in employeeArrayController.selectedObjects)
{
[[self managedObjectContext] deleteObject: employee];
}
It seems to work, but just to be sure I am checking here to see if this is indeed the correct approach?
Thanks,
- Koen.
_______________________________________________
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