Menu Item Question

Posts: 11
Joined: 2007.04
Post: #1
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).
Quote this message in a reply
Posts: 1,563
Joined: 2003.10
Post: #2
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...
Quote this message in a reply
⌘-R in Chief
Posts: 1,277
Joined: 2002.05
Post: #3
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  in-app purchase after rejected app, item with status="developer action needed" sefiroths 2 15,286 Jan 18, 2012 03:33 AM
Last Post: sefiroths
  Starting Menu: a separate event loop? ferum 11 9,441 Sep 8, 2006 03:35 AM
Last Post: imikedaman
  Fullscreen menu problem KiroNeem 2 4,238 Aug 30, 2005 02:32 PM
Last Post: KiroNeem
  Vanishing Menu Bar Prince Aron 6 6,221 May 3, 2003 03:30 PM
Last Post: OneSadCookie