View Full Version : NSPanel
Apr 28, 2011, 02:42 AM
I am using NSPanel in my application to build Modal Dialogue, but I am wondering whenever I want to handle some events it always goes to parent class but not Panel's class. I have created a Class and refereed from .NIB Object Interface.
Can you please tell how can handle Panel's control's events in Panel class itself.
Apr 28, 2011, 03:20 AM
Normally Cocoa is not programmed directly in terms of events, but instead in terms of actions sent to targets.
For example, instead of trying to code for the mouse down event on a button, you'd normally set the button's action and target so the button sends a particular action message to a particular target object when it's clicked.
Or maybe I'm being too literal with the terminology you're using in your question.
Can you tell us more about what your trying to do?
Apr 29, 2011, 12:47 AM
What I am trying to do is, When user clicks Login button there should be a window (Panel) comes out till the user respond to that Panel he/she should not be allowed to access other part of application.
But when ever I add panel to NIB the action target always goes to parent window's ".m" file not Panel's class. Can you please explain me how to direct the control to Panel's class rather parent's.
Apr 29, 2011, 03:52 AM
Have a look at the attached project. It shows 2 windows, a PanelTest window and an "Other Window" window. You might need to Cmd+` to see both windows after running in XCode.
You'll notice that you can click the Click Me button in the other window. When you do you'll see a message in the debugger console.
If you click the Login button in the PanelTest window, a login sheet will show. While the login sheet is showing, you can't click the Click Me button in the other window.
If you untick the Sheet checkbox, the login button will show a separate modal window, as opposed to a sheet.
The guts of all this is in LoginPanelController.
Note: This is an abuse of the term Panel. The login window is not an NSPanel. It's an NSWindow. Panels are used to implement secondary windows, like the Library window in Interface Builder in XCode 3 (not like the one in XCode 4).