Menu Item Question
I have a Cocoa application (i'm making a map editor) which has an open gl view subclassed in an nsscrollview. Being new to cocoa, I've been having trouble with some of the simplest things..
I have a menu item in my nib called "Grid" which I want to toggle on and off a tile grid in my open gl view. I added an action called "toggleGrid:" to firstResponder, and then added some code to implement that action in MyOpenGLView.m. This works fine after I have clicked on my view -- but before I do that it doesn't work. (I know this is because the "acceptsFirstResponder" method is only called after the view is clicked).
Am I going about this the right away? Is there a way to set my opengl view to a first responder in it's initWithFrame method, or is there a better way to go about this entirely? (you should know that my open gl view is created programmatically, so I can't set it as initialFirstResponder in IB).
I have a menu item in my nib called "Grid" which I want to toggle on and off a tile grid in my open gl view. I added an action called "toggleGrid:" to firstResponder, and then added some code to implement that action in MyOpenGLView.m. This works fine after I have clicked on my view -- but before I do that it doesn't work. (I know this is because the "acceptsFirstResponder" method is only called after the view is clicked).
Am I going about this the right away? Is there a way to set my opengl view to a first responder in it's initWithFrame method, or is there a better way to go about this entirely? (you should know that my open gl view is created programmatically, so I can't set it as initialFirstResponder in IB).
I usually do this by instantiating a controller class in the nib which receives all of the menu actions. That class is also the one that knows about the OpenGLView, so it can forward messages to it as necessary. I find that a lot more workable than trying to deal with responder chain madness...
And if you're using the document architecture, the controller object here would be the window controller (or the document itself if you did not specifically create a window controller). In that case, you still just hook up the menu item to first responder, and then implement the method in the window controller object to forward it to the view since the window controller is part of the responder chain.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| in-app purchase after rejected app, item with status="developer action needed" | sefiroths | 2 | 8,142 |
Jan 18, 2012 03:33 AM Last Post: sefiroths |
|
| Starting Menu: a separate event loop? | ferum | 11 | 4,876 |
Sep 8, 2006 03:35 AM Last Post: imikedaman |
|
| Fullscreen menu problem | KiroNeem | 2 | 2,708 |
Aug 30, 2005 02:32 PM Last Post: KiroNeem |
|
| Vanishing Menu Bar | Prince Aron | 6 | 3,901 |
May 3, 2003 03:30 PM Last Post: OneSadCookie |
|

